﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Newtonsoft.Json;
using RestFulService.pad;
using System.ServiceModel.Web;


/************************************************************************************
* Autor：xuliangxing
* Email：907562392@qq.com
* WeChart：xuliangxing
* Version：V1.0.0.0
* CreateTime：2018/4/8 13:36:40
* Description：
* Company：
* Copyright © 2018  All Rights Reserved
************************************************************************************/
namespace RestFulService
{
    // 调整 ServiceBehavior，使其支持并发
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false, IncludeExceptionDetailInFaults = true)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class PersonInfoQueryServices : IPersonInfoQuery
    {
        private List<User> UserList = new List<User>();
        DBSERVER myADO = new DBSERVER();
        LogFile Log = new LogFile();
        myredis red = new myredis();

        //配置跨域
        private void EnableCrossDmain()
        {
            var response = WebOperationContext.Current.OutgoingResponse;
            response.Headers.Add("Access-Control-Allow-Origin", "*");
            response.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
            response.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept");
            response.Headers.Add("Access-Control-Max", "1728000");
        }

        /// <summary>
        /// 生成一些测试数据
        /// </summary>
        public PersonInfoQueryServices()
        {
            
            UserList.Add(new User() { ID = 1, Name = "张三", Age = 18, Score = 98 });
            UserList.Add(new User() { ID = 2, Name = "李四", Age = 20, Score = 80 });
            UserList.Add(new User() { ID = 3, Name = "王二麻子", Age = 25, Score = 59 });
        }


        public User GetKScore()
        {
            // // 设置允许哪一个源（域）可以进行跨域访问，* 表示所有源
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            //WebOperationContext.Current.OutgoingResponse.Headers.Add("Cache-Control", "no-cache, no-store");
            // 设置允许跨域访问的请求头
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "X-Requested-With,Origin,Content-Type,Accept,Authorization");
            // 设置允许跨域访问的请求类型
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
            // 设置允许 cookie 发送到服务器 
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Credentials", "true");

            //Console.WriteLine(WebOperationContext.Current.GetType().ToString());

            string sStoreNo = WebOperationContext.Current.IncomingRequest.Headers["Authorization"];

            Console.WriteLine("跨域测试返回成功->GetKScore");

            string sId = "3";

            return UserList.FirstOrDefault(n => n.ID == int.Parse(sId));
        }
        /// <summary>
        /// 实现GetScore方法，返回某人的成绩
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public User GetScore(string name)
        {
            return UserList.FirstOrDefault(n => n.Name == name);
        }
        /// <summary>
        /// 实现GetInfo方法，返回某人的User信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public User GetInfo(Info info)
        {
            return UserList.FirstOrDefault(n => n.ID == info.ID && n.Name == info.Name);
        }

        /// <summary>
        /// 登陆接口
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public Login doLogin(LoginInfo info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "101.登陆信息..." +info.username+"/"+info.password);

            Login myLogin = new Login();
            myLogin.code = "100";
            myLogin.msg = "成功";

            Content myContent = new Content();
            myContent.storied = "";
            myContent.storeName = "";

            myLogin.content = myContent;

            try
            {
                string SQL = "  select USERNAME,PWD,b.fOrgName,b.fOrgNo"
                 + " from USERS a,Ts_Organize b"
                 + " where 1 = 1"
                 + " and a.USERID = '" + info.username + "'"
                 + " and a.FORGID = b.fOrgID";
                DataTable dtLogin = myADO.query(SQL);
                if (dtLogin is null || dtLogin.Rows.Count == 0)
                {
                    myLogin.code = "101";
                    myLogin.msg = "用户编号不存在";
                }
                else
                {
                    if (!dtLogin.Rows[0]["PWD"].ToString().Equals(info.password))
                    {
                        myLogin.code = "102";
                        myLogin.msg = "密码不正确";
                    }
                    else
                    {
                        myContent.storied = dtLogin.Rows[0]["fOrgNo"].ToString();
                        myContent.storeName = dtLogin.Rows[0]["fOrgName"].ToString();
                        myContent.EmpName = dtLogin.Rows[0]["USERNAME"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("101.登陆处理出错:" + ex.Message);
                Log.doWriteLog(1, "101.登陆处理出错:" + ex.Message);
                myLogin.code = "400";
                myLogin.msg = "101.登陆处理出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "101.登陆处理完毕");

            return myLogin;
        }

        /// <summary>
        /// 收银员接口-->改成redis获取数据
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public cashierList dogetCashierByStoreId(StoreInfo info)
        {
            try
            {
                string sKey = info.storeId + "-cashier" ;
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "102.门店:" + info.storeId + "/POS:" + info.posNo);

                //查询插入的数据
                cashierList myMenuItem = red.client.Get<cashierList>(sKey);
                if (myMenuItem is null)
                {
                    myMenuItem = new cashierList();
                    myMenuItem.code = "500";
                    myMenuItem.msg = "失败";
                    cashierList.Content myContent = new cashierList.Content();
                    myMenuItem.content = myContent;
                    Console.WriteLine("没数据:" + myMenuItem.msg.ToString());
                }
                else
                {
                    Console.WriteLine("找到有数据:" + myMenuItem.msg.ToString());
                }
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "102.菜单接口处理完毕");

                //返回
                return myMenuItem;
            }
            catch (Exception ex)
            {
                Console.WriteLine("102.菜单接口错误:" + ex.Message);

                cashierList myMenuItem = new cashierList();
                myMenuItem.code = "555";
                myMenuItem.msg = "失败:" + ex.Message;
                cashierList.Content myContent = new cashierList.Content();
                myMenuItem.content = myContent;
                return myMenuItem;
            }

        }

        /// <summary>
        /// 菜单接口-->改成redis获取数据
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public MenuItem dogetMenuByStoreId(StoreInfo info)
        {
            this.EnableCrossDmain();

            try
            {
                string sKey = string.Empty;

                if (info.posNo.Length < 4)
                {
                    sKey = info.storeId + "-" + info.posNo;
                }
                else
                {
                    sKey = info.storeId + "-" + "99";
                }
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "102.传参:" + sKey);

                //查询插入的数据
                MenuItem myMenuItem = red.client.Get<MenuItem>(sKey);
                if (myMenuItem is null)
                {
                    myMenuItem = new MenuItem();
                    myMenuItem.code = "500";
                    myMenuItem.msg = "失败";
                    MenuItem.Content myContent = new MenuItem.Content();
                    myContent.menuVersion = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    myMenuItem.content = myContent;
                    Console.WriteLine("没数据:" + myMenuItem.msg.ToString());
                }
                else
                {
                    Console.WriteLine("找到有数据:" + myMenuItem.msg.ToString());
                }
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "102.菜单接口处理完毕");

                //返回
                return myMenuItem;
            }
            catch (Exception ex)
            {
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + "102.菜单接口错误:" + ex.Message);

                MenuItem myMenuItem = new MenuItem();
                myMenuItem.code = "555";
                myMenuItem.msg = "失败:"+ex.Message;
                MenuItem.Content myContent = new MenuItem.Content();
                myContent.menuVersion = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                myMenuItem.content = myContent;
                return myMenuItem;
            }

            ////这里应该读取该门店的餐牌编号，现在先默认
            //string sMenuNo = "000504";

            //MenuItem myMenuItem = new MenuItem();

            //myMenuItem.code = "100";
            //myMenuItem.msg = "成功";

            ////第一层
            //MenuItem.Content myContent = new MenuItem.Content();
            //myContent.menuVersion = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            //myContent.menuCategoryTreeDTO = new List<MenuItem.MenuCategoryTreeDTOItem>();

            //string SQL = "select a.MENUNO,c.MENUNAME"
            // + " from Ts_ItemSession a"
            // + " INNER JOIN dbo.Ts_ItemMenu c on a.MENUNO = c.FMENUNO"
            // + " WHERE(a.WAREHID = '"+ sStoreId + "')"
            // + "   and a.posno > 90";
            //DataTable dtBigCat = myADO.query(SQL);
            //if (dtBigCat is null || dtBigCat.Rows.Count == 0)
            //{
            //    //添加第一层
            //    myMenuItem.content = myContent;

            //    return myMenuItem;
            //}

            //for (int i = 0; i < dtBigCat.Rows.Count; i++)
            //{
            //    //第二层 菜品大类
            //    MenuItem.MenuCategoryTreeDTOItem myMenuCategoryTreeDTOItem = new MenuItem.MenuCategoryTreeDTOItem();
            //    myMenuCategoryTreeDTOItem.categoryId =int.Parse(dtBigCat.Rows[i]["MENUNO"].ToString());
            //    myMenuCategoryTreeDTOItem.categoryName = dtBigCat.Rows[i]["MENUNAME"].ToString();

            //    myMenuCategoryTreeDTOItem.children = new List<MenuItem.ChildrenItem>();

            //    sMenuNo = dtBigCat.Rows[i]["MENUNO"].ToString();
            //    SQL = " select Fseq,StoName,a.FMENUNO,a.MENUNAME "
            //     + "  from Ts_ItemMenuDetail b,Ts_ItemMenu a"
            //     + "  where a.FMENUNO = '"+ sMenuNo + "'"
            //     + "  and a.FMENUNO = b.fMenuNo"
            //     + "  order by fseq";
            //    DataTable dtMidCat = myADO.query(SQL);
            //    for (int j = 0; j < dtMidCat.Rows.Count; j++)
            //    {
            //        //第三层 菜品小类
            //        MenuItem.ChildrenItem mychildren = new MenuItem.ChildrenItem();
            //        mychildren.categoryId = int.Parse(dtMidCat.Rows[j]["Fseq"].ToString()); ;
            //        mychildren.categoryName = dtMidCat.Rows[j]["StoName"].ToString(); ;

            //        mychildren.saleProductVoList = new List<MenuItem.SaleProductVoListItem>();

            //        //菜品小类下商品
            //        SQL = "  select b.fBarcode,b.fItemNo,b.fItemName,b.fSellPrice,b.fMemberPrice"
            //         + " ,b.fSaleUnit,b.fSpec,b.fItemtype,b.FDISCFLAG"
            //         + " ,b.fBClassStNo,b.fMClassStNo,b.fClassStNo"
            //         + "  from Ts_ItemMenuDetailSzi a,Ts_PLU b"
            //         + " where FMENUNO = '"+ sMenuNo + "'"
            //         + " and Fseq=" + dtMidCat.Rows[j]["Fseq"].ToString()
            //         + " and a.fitemno = b.fItemNo"
            //         + " order by Tseq,Fseq";
            //        DataTable dtMenuItem = myADO.query(SQL);
            //        for (int k = 0; k < dtMenuItem.Rows.Count; k++)
            //        {
            //            //saleProductVoList
            //            MenuItem.SaleProductVoListItem mysaleProductVoList = new MenuItem.SaleProductVoListItem();
            //            mysaleProductVoList.customerCode = dtMenuItem.Rows[k]["fItemNo"].ToString();
            //            mysaleProductVoList.erpCode = dtMenuItem.Rows[k]["fBarcode"].ToString();
            //            mysaleProductVoList.productName = dtMenuItem.Rows[k]["fItemName"].ToString();
            //            mysaleProductVoList.status = 1;
            //            mysaleProductVoList.stock = null;
            //            mysaleProductVoList.finalPrice = decimal.Parse(dtMenuItem.Rows[k]["fSellPrice"].ToString());
            //            mysaleProductVoList.memberPrice = decimal.Parse(dtMenuItem.Rows[k]["fMemberPrice"].ToString());
            //            mysaleProductVoList.promotionPrice = 0;
            //            mysaleProductVoList.picture = "http://centercoupon-dev.belray.chinafamilymart.com.cn:8087/ms/pic/masterfile/20792138.png";
            //            mysaleProductVoList.type = dtMenuItem.Rows[k]["fItemtype"].ToString();
            //            mysaleProductVoList.productGroupDTOList = null;
            //            mysaleProductVoList.materialClassIdLarge = dtMenuItem.Rows[k]["fBClassStNo"].ToString();
            //            mysaleProductVoList.materialClassIdMid = dtMenuItem.Rows[k]["fMClassStNo"].ToString();
            //            mysaleProductVoList.materialClassIdSmall = dtMenuItem.Rows[k]["fClassStNo"].ToString();
            //            mysaleProductVoList.allowFeedWayFlag = 1;
            //            mysaleProductVoList.unitName = dtMenuItem.Rows[k]["fSaleUnit"].ToString();
            //            mysaleProductVoList.addPriceBuyLog = null;
            //            mysaleProductVoList.fdiscflag =int.Parse(dtMenuItem.Rows[k]["FDISCFLAG"].ToString());

            //            //查询商品口味列表
            //            mysaleProductVoList.skuAttrGroups = new List<MenuItem.SkuAttrGroupsItem>();
            //            GetMenuAttr(dtMenuItem.Rows[k]["fItemNo"].ToString(), mysaleProductVoList);


            //            //查询套餐明细
            //            mysaleProductVoList.productGroupDTOList = new List<MenuItem.ProductGroupDTOListItem>();
            //            if (dtMenuItem.Rows[k]["fItemtype"].ToString() == "7")
            //            {
            //                //套餐商品
            //                GetBomAttr(dtMenuItem.Rows[k]["fItemNo"].ToString(), mysaleProductVoList);
            //            }

            //            //该商品加入库
            //            mychildren.saleProductVoList.Add(mysaleProductVoList);
            //        }

            //        //添加菜品小类
            //        myMenuCategoryTreeDTOItem.children.Add(mychildren);
            //    }

            // //添加菜品大类
            // myContent.menuCategoryTreeDTO.Add(myMenuCategoryTreeDTOItem);
            //}

            ////添加第一层
            //myMenuItem.content = myContent;

            //Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "102.菜单接口处理完毕");

            ////返回
            //return myMenuItem;
        }

        /// <summary>
        /// 菜单接口-->返回桌台已点菜品
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public CocoOrdList dogetOrdListByStoreId(StoreInfo info)
        {
            this.EnableCrossDmain();

            try
            {
                string sKey = info.storeId + "-" + info.posNo;
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "102.门店:" + info.storeId + "/桌台:" + info.posNo);

                ////这里应该读取该门店的餐牌编号，现在先默认
                //string sMenuNo = "000504";

                CocoOrdList myMenuItem = new CocoOrdList();

                myMenuItem.code = "100";
                myMenuItem.msg = "成功";

                ////第一层
                myMenuItem.content = new List<CocoOrdList.Content>();

                string SQL = "select fOrgNo,fOrgName,fTelNo,fOfficeAdd"
                 + " from Ts_Organize "
                 + " where forgno='" + info.storeId + "'";
                DataTable dtStore = myADO.query(SQL);
                if (dtStore is null || dtStore.Rows.Count == 0)
                {
                    return myMenuItem;
                }
                else
                {
                    myMenuItem.storeid= dtStore.Rows[0]["fOrgNo"].ToString();
                    myMenuItem.storename = dtStore.Rows[0]["fOrgName"].ToString();
                    myMenuItem.teleno = dtStore.Rows[0]["fTelNo"].ToString();
                    myMenuItem.address = dtStore.Rows[0]["fOfficeAdd"].ToString();
                }

                //第二层 菜品大类
                SQL = "select itemseq,pluno,pluName,salePrice,saleQty,saleAmt,TasteMemo"
                 + " from epos.dbo.pos_Tranflowhd"
                 + " where 1 = 1"
                 + "  and WarehouseID = '" + info.storeId + "'"
                 + "  and deskNo = '" + info.posNo + "'";
                DataTable dtDeskOrd = myADO.query(SQL);
                for (int i = 0; i < dtDeskOrd.Rows.Count; i++)
                {
                    CocoOrdList.Content mychildren = new CocoOrdList.Content();
                    mychildren.itemseq = int.Parse(dtDeskOrd.Rows[i]["itemseq"].ToString());
                    mychildren.customerCode = dtDeskOrd.Rows[i]["pluno"].ToString();
                    mychildren.foodName = dtDeskOrd.Rows[i]["pluName"].ToString();
                    mychildren.qty= decimal.Parse(dtDeskOrd.Rows[i]["saleQty"].ToString());
                    mychildren.finalPrice = decimal.Parse(dtDeskOrd.Rows[i]["salePrice"].ToString());
                    mychildren.saleAmt = decimal.Parse(dtDeskOrd.Rows[i]["saleAmt"].ToString());

                    //添加
                    myMenuItem.content.Add(mychildren);
                 }
                
                //返回
                return myMenuItem;
            }
            catch (Exception ex)
            {
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + "102.返回菜单数据错误:" + ex.Message);

                CocoOrdList myMenuItem = new CocoOrdList();
                myMenuItem.code = "555";
                myMenuItem.msg = "失败:" + ex.Message;
                return myMenuItem;
            }

            
        }


        /// <summary>
        /// coco-pos-->订单上传
        /// </summary>
        public CocoInfo doSendCoCoOrder(CocoOrder info)
        {
            this.EnableCrossDmain();

            try
            {
                string sSellWay = info.sellway;
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "103.coco点单类型:"+ sSellWay);

                string sOrdId = string.Empty;

                CocoInfo myOrdDataInfo = new CocoInfo();
                myOrdDataInfo.code = "200";
                myOrdDataInfo.msg = "操作成功";

                string sShiftFlowNo = info.ShiftNumber;//当前班别号

                //订单号
                sOrdId = info.tranNumber;

                myADO.SQLList.Clear();

                string sAccDate = DateTime.Now.ToString("yyyy-MM-dd");
                string sCashier = info.cashierId;
                string SQL = string.Empty; 
                string soperDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                Decimal tDiscAMT = 0;
                Decimal tSaleAmt = 0;
                Decimal tbeforeDiscAmt = 0;
                Decimal tafterDiscAmt = 0;

                //处理销售和退货
                if ((sSellWay.Equals("A"))|| (sSellWay.Equals("B")))
                {

                    //解析订单
                    string productInfoJson = info.productInfoJson;
                    List<CocoOrder.OrderItem> myOrdItem = JsonConvert.DeserializeObject<List<CocoOrder.OrderItem>>(info.productInfoJson);//反序列化
                    for (int i = 0; i < myOrdItem.Count; i++)
                    {
                        //Console.WriteLine(myOrdItem[i].pluName);
                        Decimal iUnitPrice = Decimal.Parse(myOrdItem[i].finalPrice.ToString()) / 100;
                        int iSaleQty = int.Parse(myOrdItem[i].qty.ToString());
                        Decimal iDiscAmt = Decimal.Parse(myOrdItem[i].DiscAMT.ToString()) / 100;
                        Decimal ibeforeDiscAmt = Decimal.Parse(myOrdItem[i].beforeDiscAmt.ToString());
                        Decimal iafterDiscAmt = Decimal.Parse(myOrdItem[i].afterDiscAmt.ToString()) / 100;
                        Decimal isaleAmt = iSaleQty * iUnitPrice - iDiscAmt;

                        tDiscAMT = tDiscAMT + iDiscAmt;
                        tSaleAmt = tSaleAmt + isaleAmt;
                        tbeforeDiscAmt = tbeforeDiscAmt + ibeforeDiscAmt;
                        tafterDiscAmt = tafterDiscAmt + iafterDiscAmt;

                        SQL = "insert into epos.dbo.pos_tranflow(WarehouseID,PosNo,flowno,itemseq,pluno"
                            + " ,unitPrice,salePrice,avPrice,saleQty,DiscAmt,beforeDiscAmt,afterDiscAmt"
                            + " ,isDirectDisc,saleAmt,SuitNo,FoodType"
                            + " ,sellWay,operId,saleMan,operDate,Uploadflag,ShiftFlowNo"
                            + " ,AccDate,DeskProperty,uniqueID,bcatno,scatno"
                            + " ,ChangePriceFlag,ChangePriceAmt,saleManName,TasteMemo"
                            + " ,DiscFlag,MemberPoint,FeedList,TCAmt,BaseAmt,MMDiscAmt"
                            + " ,tasteTotalAmt,ServiceAmt,sign,TaxID,TaxAmt,custId"
                            + " ,pluname,barcode,ulFlag,fClassStNo,fCreateDate)"
                            + " values('" + info.storeid + "','" + info.POSNO + "','" + sOrdId + "',"
                            + (i + 1).ToString()
                            + ",'" + myOrdItem[i].customerCode.ToString() + "'"
                            + "," + iUnitPrice.ToString()
                            + "," + iUnitPrice.ToString()
                            + ",0," + iSaleQty.ToString()
                            + "," + iDiscAmt.ToString()
                            + "," + ibeforeDiscAmt.ToString()
                            + "," + iafterDiscAmt.ToString()
                            + ",'" + "" + "'"
                            + "," + isaleAmt.ToString()
                            + ",'','F','A','" + sCashier + "','" + sCashier + "','" + soperDate + "','N','" + sShiftFlowNo + "'"
                            + ",'" + sAccDate + "','00',0,0,'"+myOrdItem[i].catNo.ToString()+"'"
                            + ",0,0,'" + info.POSNO + "',''"
                            + ",'N',0,'',0,0,0"
                            + ",0,0,'',0,0,'001'"
                            + ",'" + myOrdItem[i].foodName
                            + "','" + myOrdItem[i].customerCode
                            + "','0','"+myOrdItem[i].catNoBigClassNo.ToString() + "',getdate()"
                            + ")";
                        myADO.SQLList.Add(SQL);
                    }
                }

                if (sSellWay.Equals("Z"))
                {
                    //扫描点单
                    string sDeskNo = info.POSNO;

                    //获取当前桌台单号，序号
                    int iseq = 1;
                    sOrdId = "";

                    SQL = "exec PROC_POS_DOGETORDLIST '" + info.storeid + "'"
                     + ",'" + info.POSNO + "'";
                    DataTable dttran = myADO.query(SQL);
                    sOrdId = dttran.Rows[0][0].ToString();
                    iseq = int.Parse(dttran.Rows[0][1].ToString());

                    Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ",点单号:"+sOrdId);

                    //解析订单
                    string productInfoJson = info.productInfoJson;
                    List<CocoOrder.OrderItem> myOrdItem = JsonConvert.DeserializeObject<List<CocoOrder.OrderItem>>(info.productInfoJson);//反序列化
                    for (int i = 0; i < myOrdItem.Count; i++)
                    {
                        Decimal iUnitPrice = Decimal.Parse(myOrdItem[i].finalPrice.ToString()) / 100;
                        int iSaleQty = int.Parse(myOrdItem[i].qty.ToString());
                        Decimal iDiscAmt = Decimal.Parse(myOrdItem[i].DiscAMT.ToString()) / 100;
                        Decimal ibeforeDiscAmt = Decimal.Parse(myOrdItem[i].beforeDiscAmt.ToString());
                        Decimal iafterDiscAmt = Decimal.Parse(myOrdItem[i].afterDiscAmt.ToString()) / 100;
                        Decimal isaleAmt = iSaleQty * iUnitPrice - iDiscAmt;

                        tDiscAMT = tDiscAMT + iDiscAmt;
                        tSaleAmt = tSaleAmt + isaleAmt;
                        tbeforeDiscAmt = tbeforeDiscAmt + ibeforeDiscAmt;
                        tafterDiscAmt = tafterDiscAmt + iafterDiscAmt;

                        SQL = "insert into epos.dbo.pos_Tranflowhd(itemseq,flowno,siteNo,WarehouseID,pluno,pluName,unitPrice"
                         + ",salePrice,MemberPrice,saleQty,DiscAmt,isDirectDisc,DiscStr"
                         + ",DiscStrExt,saleAmt,suitIndex,SuitNo,FoodType,orgSuitDetail"
                         + ",DiscFlag,PrintFlag,PrintName,orgPrice,sellWay,operId"
                         + ",saleMan,operDate,TasteMemo,tasteTotalAmt,TasteList"
                         + ",plusubname,Uploadflag,changePxFlag,orgUnitPrice"
                         + ",CanPrintBill,FlagGroup,bcatno,scatno,ChangePriceFlag"
                         + ",ChangePriceAmt,mpluno,printCnt,MemberPoint,CardNo"
                         + ",sign,deskNo,ServiceAmt,CustID,PosNo"
                         + ",ulFlag,tasteHand,isInRoom)"
                         +" values("+(iseq+i).ToString()
                         +",'"+ sOrdId.ToString()+"'"
                         +",0,'"+info.storeid+"'"
                         + ",'" + myOrdItem[i].customerCode.ToString() + "'"
                         + ",'" + myOrdItem[i].foodName.ToString() + "'"
                         +","+ iUnitPrice.ToString()
                         +","+ iUnitPrice.ToString()
                         +",0,"+ iSaleQty.ToString()
                         +","+ tDiscAMT.ToString()+",0,0,0"
                         +","+ tSaleAmt.ToString()+",0,0,'F',0,'Y','N','NONE'"
                         +","+ iUnitPrice.ToString()+",'A','"+info.POSNO+"'"
                         +",'"+info.POSNO+"',getdate(),'',0,'','','N','',0"
                         +",'Y','','"+myOrdItem[i].catNoBigClassNo+"','"+myOrdItem[i].catNo+"'"
                         +",'Y',0,0,0,0,0,0,'"+info.POSNO+"',0,0,0"
                         +",0,0,'Y')";
                        myADO.SQLList.Add(SQL);
                    }
                }
                else
                {
                    SQL = "insert into epos.dbo.pos_tranhead(Accdate,Warehouseid,Flowno,Sellway"
                        + " ,GrosalAMT,DiscAMT,SaleAmt,OverAmt,ChgAmt,beforeDiscAmt,afterDiscAmt"
                        + "  ,operId,OperDate,saleMan,isInRoom,Deskproperty"
                        + "  ,CustNumber,CustManNumber,CustWoManNumber,CustChildNumber,CustWoMan,CustZWoman,CustYWoman,CustOMan,CustOWoman"
                        + "  ,ShiftFlowNo,uploadFlag,custId,MMDiscAmt,AccFlag,PosNo"
                        + "  ,tasteAmt,vipNo,vippoint,vippointToMoney,HaveServiceAmt,TaxAmt,fCreateDate,deskNo,ulFlag)"
                        + " values('" + sAccDate + "','" + info.storeid + "','" + sOrdId + "','" + sSellWay + "'"
                        + " ," + (tSaleAmt + tDiscAMT).ToString()
                        + "," + tDiscAMT.ToString()
                        + "," + tSaleAmt.ToString()
                        + ",0,0," + tbeforeDiscAmt.ToString() + "," + tafterDiscAmt.ToString()
                        + ",'" + sCashier + "','" + soperDate + "','" + sCashier
                        + "'," + "'Z'" + ",'00'"
                        + ",1,1,0,0,0,0,0,0,0"
                        + ",'" + sShiftFlowNo + "','N','101',0,'0','" + info.POSNO + "'"
                        + ",0,'" + info.memberno + "',0,0,0,0,getdate(),'00',0"
                        + ")";
                    myADO.SQLList.Add(SQL);
                }

                bool IsOk = false;
                string sError = string.Empty;
                myADO.doSave(out IsOk, out sError);

                //if (IsOk)
                //{
                //    SQL = " exec Proc_SetPosOrder '" + info.storeId + "','" + sOrdId + "'";
                //    myADO.doexec(SQL);
                //}
                //返回
                CocoInfo.Content myContent = new CocoInfo.Content();
                myContent.payPrice = 0;
                myContent.orderId = sOrdId;

                if (!IsOk)
                {
                    myOrdDataInfo.code = "100";
                    myContent.payPrice = 0;
                    myContent.orderId = "";
                }
                
                myOrdDataInfo.msg = sError;
                myOrdDataInfo.content = myContent;
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "103.coco点单处理完毕," + sOrdId);
                return myOrdDataInfo;
            }
            catch (Exception ex)
            {
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() +"103.交易上传出错:" + ex.Message);
                Log.doWriteLog(1, "103.交易上传出错:" + ex.Message);
                CocoInfo myOrdDataInfo = new CocoInfo();
                myOrdDataInfo.code = "100";
                myOrdDataInfo.msg = "交易出错:" + ex.Message;
                return myOrdDataInfo;
            }

        }


        /// <summary>
        /// 扫描点单上传
        /// </summary>
        public OrdDataInfo doSetOrder(ScanOrder info)
        {
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept");

            try
            {
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "103.扫描点单..." + info.storeId + "/" + info.posNo + "/" + info.saleAmt);

                string sOrdId = string.Empty;

                OrdDataInfo myOrdDataInfo = new OrdDataInfo();
                myOrdDataInfo.code = "100";
            
                string sShiftFlowNo = info.posNo + DateTime.Now.ToString("yyyyMMdd") + "0001";//当前班别号
                
                //订单号
                string SQL = "declare @pNo varchar(20),@pId varchar(20)"
                    + "  exec proc_getbillNo 6,@pId output, @pNo output"
                    + "  select @pNo";
                DataTable dtBillNo = myADO.query(SQL);
                sOrdId = dtBillNo.Rows[0][0].ToString();

                myADO.SQLList.Clear();

                string sAccDate = DateTime.Now.ToString("yyyy-MM-dd");
                string sCashier = "999999";

                //解析订单
                //string productInfoJson = info.productInfoJson;
                //List<ScanOrder.OrderItem> myOrdItem = JsonConvert.DeserializeObject<List<ScanOrder.OrderItem>>(info.productInfoJson);//反序列化
                for (int i = 0; i < info.productInfoJson.Count; i++)
                {
                    //Console.WriteLine(myOrdItem[i].pluName);
                    SQL = "insert into epos.dbo.pos_tranflow(WarehouseID,PosNo,flowno,itemseq,pluno"
                        + " ,unitPrice,salePrice,avPrice,saleQty,DiscAmt,beforeDiscAmt,afterDiscAmt"
                        + " ,isDirectDisc,saleAmt,SuitNo,FoodType"
                        + " ,sellWay,operId,saleMan,operDate,Uploadflag,ShiftFlowNo"
                        + " ,AccDate,DeskProperty,uniqueID,bcatno,scatno"
                        + " ,ChangePriceFlag,ChangePriceAmt,saleManName,TasteMemo"
                        + " ,DiscFlag,MemberPoint,FeedList,TCAmt,BaseAmt,MMDiscAmt"
                        + " ,tasteTotalAmt,ServiceAmt,sign,TaxID,TaxAmt,custId"
                        + " ,pluname,barcode,ulFlag,fClassStNo,fCreateDate)"
                        + " values('" + info.storeId + "','" + info.posNo + "','" + sOrdId + "',"
                        + info.productInfoJson[i].flineno.ToString()
                        + ",'" + info.productInfoJson[i].customerCode + "'"
                        + "," + info.productInfoJson[i].originalPrice.ToString()
                        + "," + info.productInfoJson[i].pluPrice.ToString()
                        + ",0," + info.productInfoJson[i].qty.ToString()
                        + "," + info.productInfoJson[i].promBeforeDiscAmt.ToString() + "+" + info.productInfoJson[i].promAfterDiscAmt.ToString()
                        + "," + info.productInfoJson[i].promBeforeDiscAmt.ToString()
                        + "," + info.productInfoJson[i].promAfterDiscAmt.ToString()
                        + ",'" + "" + "'"
                        + "," + info.productInfoJson[i].saleAmt.ToString()
                        + ",'','" + info.productInfoJson[i].type.ToString() + "','A','" + sCashier + "','" + sCashier + "','" + info.systemdate + "','N','" + sShiftFlowNo + "'"
                        + ",'" + sAccDate + "','00',0,0,0"
                        + ",0,0,'" + info.posNo + "',''"
                        + ",'N',0,'',0,0,0"
                        + ",0,0,'',0,0,'001'"
                        + ",'" + info.productInfoJson[i].pluName + "','" + info.productInfoJson[i].erpCode + "','0',0,getdate()"
                        + ")";
                    myADO.SQLList.Add(SQL);
                }

                SQL = "insert into epos.dbo.pos_tranhead(Accdate,Warehouseid,Flowno,Sellway"
                    + " ,GrosalAMT,DiscAMT,SaleAmt,OverAmt,ChgAmt,beforeDiscAmt,afterDiscAmt"
                    + "  ,operId,OperDate,saleMan,isInRoom,Deskproperty"
                    + "  ,CustNumber,CustManNumber,CustWoManNumber,CustChildNumber,CustWoMan,CustZWoman,CustYWoman,CustOMan,CustOWoman"
                    + "  ,ShiftFlowNo,uploadFlag,custId,MMDiscAmt,AccFlag,PosNo"
                    + "  ,tasteAmt,vipNo,vippoint,vippointToMoney,HaveServiceAmt,TaxAmt,fCreateDate,deskNo,ulFlag)"
                    + " values('" + sAccDate + "','" + info.storeId + "','" + sOrdId + "','A'"
                    + " ," + info.saleAmt.ToString() + "+" + info.promBeforeDiscAmt.ToString()
                    + "," + info.promBeforeDiscAmt.ToString()
                    + "," + info.saleAmt.ToString()
                    + ",0,0,0,0"
                    + ",'" + sCashier + "','" + info.systemdate + "','" + sCashier + "'," + "'Z'" + ",'00'"
                    + ",1,1,0,0,0,0,0,0,0"
                    + ",'" + sShiftFlowNo + "','N','101',0,'0','" + info.posNo + "'"
                    + ",0,'" + info.memberno + "',0,0,0,0,getdate(),'"+info.deskNo+"',0"
                    + ")";
                myADO.SQLList.Add(SQL);
                              

                bool IsOk = false;
                string sError = string.Empty;
                myADO.doSave(out IsOk, out sError);

                if (IsOk)
                {
                    SQL = " exec Proc_SetPosOrder '" + info.storeId + "','" + sOrdId + "'";
                    myADO.doexec(SQL);
                }
                //返回
                OrdDataInfo.Content myContent = new OrdDataInfo.Content();
                myContent.payPrice = 0;
                myContent.orderId = sOrdId;

                if (!IsOk)
                {
                    myOrdDataInfo.code = "100";
                    myContent.payPrice = 0;
                    myContent.orderId = "";
                }
                myOrdDataInfo.msg = sError;
                myOrdDataInfo.content = myContent;
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "103.扫描点单处理完毕," + sOrdId);
                return myOrdDataInfo;
            }
            catch (Exception ex)
            {
                Console.WriteLine("103.交易上传出错:" + ex.Message);
                Log.doWriteLog(1, "103.交易上传出错:" + ex.Message);
                OrdDataInfo myOrdDataInfo = new OrdDataInfo();
                myOrdDataInfo.code = "100";
                myOrdDataInfo.code = "400";
                myOrdDataInfo.msg = "交易出错:"+ex.Message;
                return myOrdDataInfo;
            }
            
        }

        /// <summary>
        /// 扫描点单--获取token
        /// </summary>
        public deskToken dogetToken(deskPara info)
        {
            try
            {
                string sKey = info.storeId ;
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "102.门店token:" + info.storeId );

                deskToken myToken = new deskToken();

                //查询插入的数据
                deskStore myMenuItem = red.client.Get<deskStore>(sKey);
                if (myMenuItem is null)
                {
                    myToken.code = "500";
                    myToken.msg = "失败";
                    myToken.data = "";
                    Console.WriteLine("没数据:" + myToken.msg.ToString());
                }
                else
                {
                    myToken.code = "200";
                    myToken.msg = "ok";
                    myToken.data = myMenuItem.Easycardstoreid.ToString();
                    Console.WriteLine("找到有数据:" + myMenuItem.Easycardstoreid.ToString());
                }

                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "102.门店token..." + myMenuItem.Easycardstoreid.ToString());

                return myToken;
            }
            catch (Exception ex)
            {
                Console.WriteLine("102.门店token:" + ex.Message);
                Log.doWriteLog(1, "102.门店token:" + ex.Message);
                deskToken myToken = new deskToken();
                myToken.code = "500";
                myToken.msg = "失败";
                myToken.data = "";
                return myToken;
            }
            
        }

        /// <summary>
        /// POS获取扫描点单
        /// </summary>
        public deskOrder doScanOrdList()
        {
            try
            {
                string sStoreNo = WebOperationContext.Current.IncomingRequest.Headers["Authorization"];
                //string sStoreNo = Authorization;
                sStoreNo = sStoreNo.Replace("Bearer", "");
                sStoreNo = sStoreNo.Trim();
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "准备检索订单:" + sStoreNo);

                deskOrder mydeskOrder = new deskOrder();

                mydeskOrder.code = "200";
                mydeskOrder.msg = "OK";

                deskOrderData mydeskData = new deskOrderData();
                mydeskData.currentPage = 0;
                mydeskData.totalPages = 0;
                mydeskData.pageSize = 10;
                mydeskData.totalCount = 0;
                mydeskData.hasPrevious = false;
                mydeskData.hasNext = false;

                mydeskData.rows = new List<OrderHead>();

                string SQL = " select * from epos.dbo.pos_tranhead "
                  + " where Warehouseid = '"+ sStoreNo + "'"
                  + " and PosNo = '99'"
                  + " and CONVERT(varchar(10),operDate,120)= CONVERT(varchar(10), GETDATE(), 120)"
                  + " and ulFlag = 0"
                  + " order by flowno";
                DataTable dtHead = myADO.query(SQL);
                for (int i = 0; i < dtHead.Rows.Count; i++)
                {
                    OrderHead myOrderHead = new OrderHead();
                    myOrderHead.billtype = "Z";
                    myOrderHead.id = i;
                    myOrderHead.payover = 0;
                    myOrderHead.deskno = dtHead.Rows[i]["deskNo"].ToString();
                    myOrderHead.warehouseid = dtHead.Rows[i]["warehouseid"].ToString();
                    myOrderHead.channelsheetno= dtHead.Rows[i]["flowno"].ToString();
                    myOrderHead.ordertime = dtHead.Rows[i]["OperDate"].ToString();
                    myOrderHead.createtime = dtHead.Rows[i]["OperDate"].ToString();
                    myOrderHead.updatetime = dtHead.Rows[i]["OperDate"].ToString();
                    myOrderHead.weight = 0;
                    myOrderHead.packagefee = 0;
                    myOrderHead.totalsalevalue = ExtendedNumerics.BigDecimal.Parse(dtHead.Rows[i]["SaleAmt"].ToString());
                    myOrderHead.totaldiscvalue = 0;
                    myOrderHead.totalsjdisc = 0;
                    myOrderHead.totalptdisc = 0;
                    myOrderHead.totalsjdp = 0;
                    myOrderHead.totalptdp = 0;
                    myOrderHead.commissionvalue = 0;
                    myOrderHead.payablevalue = Decimal.Parse(dtHead.Rows[i]["SaleAmt"].ToString());
                    myOrderHead.totalitemvalue = 0;
                    myOrderHead.payablelogisticsvalue = 0;
                    myOrderHead.orderseq = i;
                    myOrderHead.tastetotalamt = Decimal.Parse(dtHead.Rows[i]["SaleAmt"].ToString());
                    myOrderHead.serviceamt = 0;
                    myOrderHead.invoicemoney = 0;
                    myOrderHead.serviceamt = 0;
                    myOrderHead.lunchboxfee = 0;
                    myOrderHead.tastetotalamt = 0;
                    myOrderHead.custnumber = 1;
                    myOrderHead.isinroom = "N";
                    myOrderHead.uploadflag = "N";
                    myOrderHead.status = "0";
                    myOrderHead.sellway= dtHead.Rows[i]["sellway"].ToString();
                    myOrderHead.roomno = dtHead.Rows[i]["roomno"].ToString();
                    myOrderHead.deskno = dtHead.Rows[i]["deskno"].ToString();

                    myOrderHead.orderdetail = new List<OrderDTL>();

                    SQL = "select a.*,b.foodname,b.printflag,b.printerName,b.printerNameExt1,b.printerNameExt2 "
                     + " from epos.dbo.pos_tranflow a,epos.dbo.tbl_foodinfo b"
                     + " where a.Warehouseid = '" + sStoreNo + "'"
                     + " and a.PosNo = '99'"
                     + " and flowno='"+ dtHead.Rows[i]["flowno"].ToString() + "'"
                     + " and a.Warehouseid=b.Warehouseid"
                     + " and a.pluno=b.itemno";
                    DataTable dtDTL = myADO.query(SQL);
                    if ((!(dtDTL is null)) && (dtDTL.Rows.Count > 0))
                    {
                        for (int j = 0; j < dtDTL.Rows.Count; j++)
                        {
                            OrderDTL myOrderDTL = new OrderDTL();
                            myOrderDTL.id = int.Parse(dtDTL.Rows[j]["itemseq"].ToString());
                            myOrderDTL.headid = int.Parse(dtDTL.Rows[j]["itemseq"].ToString());
                            myOrderDTL.channelsheetno = dtDTL.Rows[j]["flowno"].ToString();
                            myOrderDTL.itemcode = dtDTL.Rows[j]["pluno"].ToString();
                            myOrderDTL.barcode = dtDTL.Rows[j]["mpluno"].ToString();
                            myOrderDTL.pluname = dtDTL.Rows[j]["foodname"].ToString();
                            myOrderDTL.qriginalprice = decimal.Parse(dtDTL.Rows[j]["salePrice"].ToString());
                            myOrderDTL.weight = 1;
                            myOrderDTL.saleprice = decimal.Parse(dtDTL.Rows[j]["salePrice"].ToString());
                            myOrderDTL.discvalue = 0;
                            myOrderDTL.discvaluept = 0;
                            myOrderDTL.discbtsj = 0;
                            myOrderDTL.discbt = 0;
                            myOrderDTL.commissionvalue = 0;
                            myOrderDTL.qty = decimal.ToInt16(decimal.Parse(dtDTL.Rows[j]["saleQty"].ToString()));
                            myOrderDTL.money = decimal.Parse(dtDTL.Rows[j]["saleAmt"].ToString());
                            myOrderDTL.posqty = 0;
                            myOrderDTL.electronicgoods = 0;
                            myOrderDTL.coefficient = 0;
                            myOrderDTL.activityid = "";
                            myOrderDTL.supplierrate = 0;
                            myOrderDTL.posprice = 0;
                            myOrderDTL.seq = int.Parse(dtDTL.Rows[j]["itemseq"].ToString());
                            myOrderDTL.uploadflag = "N";
                            myOrderDTL.suitno = dtDTL.Rows[j]["SuitNo"].ToString();
                            myOrderDTL.foodtype = dtDTL.Rows[j]["FoodType"].ToString();
                            myOrderDTL.bcatno = dtDTL.Rows[j]["bcatno"].ToString();
                            myOrderDTL.scatno = dtDTL.Rows[j]["scatno"].ToString();
                            myOrderDTL.classstno = dtDTL.Rows[j]["fclassstno"].ToString();
                            myOrderDTL.sellway = dtDTL.Rows[j]["sellway"].ToString();
                            myOrderDTL.taste= dtDTL.Rows[j]["TasteMemo"].ToString();
                            myOrderDTL.printtype = dtDTL.Rows[j]["printflag"].ToString();
                            myOrderDTL.printname = dtDTL.Rows[j]["printerName"].ToString();
                            myOrderDTL.printnameext1 = dtDTL.Rows[j]["printerNameExt1"].ToString();
                            myOrderDTL.printnameext2 = dtDTL.Rows[j]["printerNameExt2"].ToString();
                            myOrderDTL.couponid = "";
                            myOrderDTL.suitindex = "";
                            myOrderDTL.suitno = "";
                            myOrderDTL.comment = "";

                            //加入商品明细
                            myOrderHead.orderdetail.Add(myOrderDTL);
                        }
                    }

                    //支付信息
                    myOrderHead.orderpay = new List<OrderPAY>();

                    SQL = "select * "
                     + " from epos.dbo.pos_tranpay a"
                     + " where a.Warehouseid = '" + sStoreNo + "'"
                     + " and PosNo = '99'"
                     + " and flowno='" + dtHead.Rows[i]["flowno"].ToString() + "'";
                    DataTable dtPAY = myADO.query(SQL);
                    if ((!(dtPAY is null)) && (dtPAY.Rows.Count >0))
                    {
                        for (int k = 0; k < dtPAY.Rows.Count; k++)
                        {
                            OrderPAY myOrderPAY = new OrderPAY();
                            myOrderPAY.id = int.Parse(dtPAY.Rows[k]["itemseq"].ToString());
                            myOrderPAY.headid = int.Parse(dtPAY.Rows[k]["itemseq"].ToString());
                            myOrderPAY.channelsheetno = dtPAY.Rows[k]["flowno"].ToString();
                            myOrderPAY.payno = dtPAY.Rows[k]["payWay"].ToString();
                            myOrderPAY.name = dtPAY.Rows[k]["coinNo"].ToString();
                            myOrderPAY.seq = int.Parse(dtPAY.Rows[k]["itemseq"].ToString());
                            myOrderPAY.payment = decimal.Parse(dtPAY.Rows[k]["saleAmt"].ToString()); ;
                            myOrderPAY.uploadflag = "N";

                            //加入支付明细
                            myOrderHead.orderpay.Add(myOrderPAY);
                        }
                    }

                    //加入一笔交易
                    mydeskData.rows.Add(myOrderHead);
                }

                mydeskOrder.data = mydeskData;
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "完成检索订单:" + sStoreNo);

                return mydeskOrder;
            }
            catch (Exception ex)
            {
                Console.WriteLine("102.POS获取扫描点单:" + ex.Message);
                Log.doWriteLog(1, "102.POS获取扫描点单:" + ex.Message);
                deskOrder mydeskOrder = new deskOrder();
                mydeskOrder.code = "400";
                mydeskOrder.msg = "错误";
                return mydeskOrder;
            }

        }

        /// <summary>
        /// POS扫描取单
        /// </summary>
        public deskReturn doScanGetOrd(string channelsheetno)
        {
            try
            {
                string sStoreNo = WebOperationContext.Current.IncomingRequest.Headers["Authorization"];
                //string sStoreNo = Authorization;

                deskReturn mydeskReturn = new deskReturn();
                mydeskReturn.code = 200;
                mydeskReturn.msg = "成功";

                string SQL = " update epos.dbo.pos_tranhead "
                  + " set ulFlag = 1"
                  + " where Warehouseid = '" + sStoreNo + "'"
                  + " and PosNo = '99'"
                  + " and flowno='"+ channelsheetno + "'";
                myADO.doexec(SQL);

                return mydeskReturn;
            }
            catch (Exception ex)
            {
                Console.WriteLine("102.POS获取扫描点单:" + ex.Message);
                Log.doWriteLog(1, "102.POS获取扫描点单:" + ex.Message);
                deskReturn mydeskReturn = new deskReturn();
                mydeskReturn.code = 400;
                mydeskReturn.msg = "失败";
                return mydeskReturn;
            }

        }

        /// <summary>
        /// 商品口味
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        private void GetMenuAttr(string sItemNo,MenuItem.SaleProductVoListItem mysaleProductVoList)
        {
            string SQL = " select a.TASTECATNO,b.TASTECATNAME"
                         + " from ts_itemtaste a"
                         + " JOIN tbl_tasteReasonCat b  ON a.TASTECATNO = b.TasteCatno"
                         + " JOIN tbl_tasteReason c ON a.TASTENO = c.TasteNo"
                         + " WHERE a.FITEMNO = '" + sItemNo + "'"
                         + " group by a.TASTECATNO,b.TASTECATNAME";
            DataTable dtItemAttr1 = myADO.query(SQL);
            if (dtItemAttr1 is null || dtItemAttr1.Rows.Count == 0)
            {
                //Console.WriteLine("没有口味");
            }
            else
            {
                for (int l = 0; l < dtItemAttr1.Rows.Count; l++)
                {
                    MenuItem.SkuAttrGroupsItem myskuAttrGroups = new MenuItem.SkuAttrGroupsItem();
                    myskuAttrGroups.skuId = dtItemAttr1.Rows[l]["TASTECATNO"].ToString() + "'";
                    myskuAttrGroups.groupId = dtItemAttr1.Rows[l]["TASTECATNO"].ToString() + "'";
                    myskuAttrGroups.groupName = dtItemAttr1.Rows[l]["TASTECATNAME"].ToString() + "'";
                    myskuAttrGroups.choices = 0;
                    myskuAttrGroups.required = 1;

                    myskuAttrGroups.propertyList = new List<MenuItem.PropertyListItem>();

                    SQL = " select a.TASTECATNO,a.TASTENO,b.TASTECATNAME,c.TasteName,convert(numeric(7,0),c.ChangeAmt) ChangeAmt"
                     + " from ts_itemtaste a"
                     + " JOIN tbl_tasteReasonCat b  ON a.TASTECATNO = b.TasteCatno"
                     + " JOIN tbl_tasteReason c ON a.TASTENO = c.TasteNo"
                     + " WHERE a.FITEMNO = '" + sItemNo + "'"
                     + " and a.TASTECATNO='" + dtItemAttr1.Rows[l]["TASTECATNO"].ToString() + "'";
                    DataTable dtItemAttr2 = myADO.query(SQL);
                    for (int m = 0; m < dtItemAttr2.Rows.Count; m++)
                    {
                        MenuItem.PropertyListItem mypropertyList = new MenuItem.PropertyListItem();
                        mypropertyList.groupId = dtItemAttr2.Rows[m]["TASTENO"].ToString();
                        mypropertyList.propertyId = dtItemAttr2.Rows[m]["TASTENO"].ToString();
                        mypropertyList.propertyName = dtItemAttr2.Rows[m]["TasteName"].ToString();
                        mypropertyList.salePrice = "0";
                        mypropertyList.addPrice = int.Parse(dtItemAttr2.Rows[m]["ChangeAmt"].ToString());
                        mypropertyList.feedId = dtItemAttr2.Rows[m]["TASTENO"].ToString();
                        mypropertyList.feedNum = dtItemAttr2.Rows[m]["TASTENO"].ToString();
                        mypropertyList.feedName = dtItemAttr2.Rows[m]["TasteName"].ToString();
                        mypropertyList.feedNum = "1";
                        mypropertyList.defaultFlag = m;
                        //口味明细
                        myskuAttrGroups.propertyList.Add(mypropertyList);
                    }

                    //添加商品口味
                    mysaleProductVoList.skuAttrGroups.Add(myskuAttrGroups);
                }

            }
        }

        /// <summary>
        /// 商品套餐:套餐分类+套餐明细+商品口味
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        private void GetBomAttr(string sItemNo, MenuItem.SaleProductVoListItem mysaleProductVoList)
        {
            //套餐分类
            string SQL = " select findex,b.fItemNo,c.fClassStName,convert(int,a.ITEMQTY) ITEMQTY"
               + "  from Ts_ItemPackChip a,Ts_PLU b, Ts_ClassStore c"
               + "  where SUITNO = '"+ sItemNo+"'"
               + " and a.fItemNo = b.fItemNo"
               + " and b.fClassStNo = c.fClassStNo"
               + " order by findex";
            DataTable dtItemAttr1 = myADO.query(SQL);
            if (dtItemAttr1 is null || dtItemAttr1.Rows.Count == 0)
            {
                //Console.WriteLine("没有套餐");
            }
            else
            {
                for (int l = 0; l < dtItemAttr1.Rows.Count; l++)
                {
                    MenuItem.ProductGroupDTOListItem myproductGroupDTOList = new MenuItem.ProductGroupDTOListItem();
                    myproductGroupDTOList.productId = dtItemAttr1.Rows[l]["fItemNo"].ToString();
                    myproductGroupDTOList.groupId = dtItemAttr1.Rows[l]["fItemNo"].ToString();
                    myproductGroupDTOList.groupName = dtItemAttr1.Rows[l]["fClassStName"].ToString() ;
                    myproductGroupDTOList.allowRepeat = 1;
                    myproductGroupDTOList.sequence = dtItemAttr1.Rows[l]["findex"].ToString();

                    myproductGroupDTOList.skuInfoDTOList = new List<MenuItem.SkuInfoDTOListItem>();
                    
                    //套餐明细
                    SQL = " select  PARENTITEMNO,b.fbarcode,b.fItemNo,b.fItemName"
                     + " ,a.CHANGEAMT"
                     + " ,b.fBClassStNo,b.fMClassStNo,b.fClassStNo,b.fItemType"
                     + " ,b.fSellPrice,b.fSaleUnit"
                     + " from Ts_ItemPackChipDetail a,Ts_PLU b"
                     + " where SUITNO =  '" + sItemNo + "'"
                     + " and a.PARENTITEMNO='" + dtItemAttr1.Rows[l]["fItemNo"].ToString() + "'"
                     + "  and a.fItemNo = b.fItemNo"
                     +"  order by PARENTITEMNO,FINDEX"   ;
                    DataTable dtItemAttr2 = myADO.query(SQL);
                    for (int m = 0; m < dtItemAttr2.Rows.Count; m++)
                    {
                        MenuItem.SkuInfoDTOListItem myskuInfoDTOList = new MenuItem.SkuInfoDTOListItem();
                        myskuInfoDTOList.customerCode = dtItemAttr2.Rows[m]["fItemNo"].ToString();
                        myskuInfoDTOList.skuId = dtItemAttr2.Rows[m]["fItemNo"].ToString();
                        myskuInfoDTOList.erpCode = dtItemAttr2.Rows[m]["fbarcode"].ToString();
                        myskuInfoDTOList.onlineName = dtItemAttr2.Rows[m]["fItemName"].ToString();
                        myskuInfoDTOList.subtitle = dtItemAttr2.Rows[m]["fItemName"].ToString();
                        myskuInfoDTOList.materialCategoryId = dtItemAttr2.Rows[m]["fBClassStNo"].ToString();
                        myskuInfoDTOList.materialClassIdMid = dtItemAttr2.Rows[m]["fMClassStNo"].ToString();
                        myskuInfoDTOList.materialClassIdSmall = dtItemAttr2.Rows[m]["fMClassStNo"].ToString();
                        myskuInfoDTOList.saleUnit = dtItemAttr2.Rows[m]["fSaleUnit"].ToString();
                        myskuInfoDTOList.salePrice = decimal.Parse(dtItemAttr2.Rows[m]["fSellPrice"].ToString());
                        myskuInfoDTOList.promotionPrice = 0;
                        myskuInfoDTOList.saleStatus = 1;
                        myskuInfoDTOList.addPrice =decimal.Parse(dtItemAttr2.Rows[m]["CHANGEAMT"].ToString());
                        myskuInfoDTOList.type = dtItemAttr2.Rows[m]["fItemType"].ToString();
                        myskuInfoDTOList.qty = int.Parse(dtItemAttr1.Rows[l]["ITEMQTY"].ToString());

                        //该商品口味
                        myskuInfoDTOList.skuAttrGroups = new List<MenuItem.SkuAttrGroupsItem>();
                        SQL = " select a.TASTECATNO,b.TASTECATNAME"
                         + " from ts_itemtaste a"
                         + " JOIN tbl_tasteReasonCat b  ON a.TASTECATNO = b.TasteCatno"
                         + " JOIN tbl_tasteReason c ON a.TASTENO = c.TasteNo"
                         + " WHERE a.FITEMNO = '" + dtItemAttr2.Rows[m]["fItemNo"].ToString() + "'"
                         + " group by a.TASTECATNO,b.TASTECATNAME";
                        DataTable dtItemAttr3 = myADO.query(SQL);
                        if (dtItemAttr3 is null || dtItemAttr3.Rows.Count == 0)
                        {
                            //Console.WriteLine("没有口味");
                        }
                        else
                        {
                            for (int i = 0; i < dtItemAttr3.Rows.Count; i++)
                            {
                                MenuItem.SkuAttrGroupsItem myskuAttrGroups = new MenuItem.SkuAttrGroupsItem();
                                myskuAttrGroups.skuId = dtItemAttr3.Rows[i]["TASTECATNO"].ToString() + "'";
                                myskuAttrGroups.groupId = dtItemAttr3.Rows[i]["TASTECATNO"].ToString() + "'";
                                myskuAttrGroups.groupName = dtItemAttr3.Rows[i]["TASTECATNAME"].ToString() + "'";
                                myskuAttrGroups.choices = 1;
                                myskuAttrGroups.required = 1;

                                myskuAttrGroups.propertyList = new List<MenuItem.PropertyListItem>();

                                SQL = " select a.TASTECATNO,a.TASTENO,b.TASTECATNAME,c.TasteName,convert(numeric(7,0),c.ChangeAmt) ChangeAmt"
                                 + " from ts_itemtaste a"
                                 + " JOIN tbl_tasteReasonCat b  ON a.TASTECATNO = b.TasteCatno"
                                 + " JOIN tbl_tasteReason c ON a.TASTENO = c.TasteNo"
                                 + " WHERE a.FITEMNO = '" + dtItemAttr2.Rows[m]["fItemNo"].ToString() + "'"
                                 + " and a.TASTECATNO='" + dtItemAttr3.Rows[i]["TASTECATNO"].ToString() + "'";
                                DataTable dtItemAttr4 = myADO.query(SQL);
                                for (int j = 0; j < dtItemAttr4.Rows.Count; j++)
                                {
                                    MenuItem.PropertyListItem mypropertyList = new MenuItem.PropertyListItem();
                                    mypropertyList.groupId = dtItemAttr4.Rows[j]["TASTENO"].ToString();
                                    mypropertyList.propertyId = dtItemAttr4.Rows[j]["TASTENO"].ToString();
                                    mypropertyList.propertyName = dtItemAttr4.Rows[j]["TasteName"].ToString();
                                    mypropertyList.salePrice = "0";
                                    mypropertyList.addPrice = int.Parse(dtItemAttr4.Rows[j]["ChangeAmt"].ToString());
                                    mypropertyList.feedId = dtItemAttr4.Rows[j]["TASTENO"].ToString();
                                    mypropertyList.feedNum = dtItemAttr4.Rows[j]["TASTENO"].ToString();
                                    mypropertyList.feedName = dtItemAttr4.Rows[j]["TasteName"].ToString();
                                    mypropertyList.feedNum = "1";
                                    mypropertyList.defaultFlag = j;

                                    //口味明细
                                    myskuAttrGroups.propertyList.Add(mypropertyList);
                                }

                                //添加商品口味
                                myskuInfoDTOList.skuAttrGroups.Add(myskuAttrGroups);
                            }
                        }

                        //套餐明细
                        myproductGroupDTOList.skuInfoDTOList.Add(myskuInfoDTOList);
                    }

                    //添加套餐分类
                    mysaleProductVoList.productGroupDTOList.Add(myproductGroupDTOList);

                }

            }
        }

        /// <summary>
        /// 200.检查当前是否已开班
        /// </summary>
        public ShiftReturn doCheckShift(ShiftInfo info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "200.检查开班..." + info.storeid + "/" + info.posno);

            ShiftReturn myShiftReturn = new ShiftReturn();
            myShiftReturn.code = "100";
            myShiftReturn.msg = "成功";

            try
            {
                string SQL = "exec PROC_POS_DOCHECKSHIFT '" + info.storeid + "'"
                   + ",'" + info.posno + "'"
                   + ",'" + info.userid + "'";
                DataTable dttran = myADO.query(SQL);
                myShiftReturn.code = dttran.Rows[0][0].ToString();
                myShiftReturn.msg = dttran.Rows[0][1].ToString();
                myShiftReturn.storied = dttran.Rows[0][2].ToString();
                myShiftReturn.posno = dttran.Rows[0][3].ToString();
                myShiftReturn.shiftstate = dttran.Rows[0][4].ToString();
                myShiftReturn.shiftno = dttran.Rows[0][5].ToString();
                myShiftReturn.shiftamt = decimal.Parse(dttran.Rows[0][6].ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine("200.检查开班:" + ex.Message);
                Log.doWriteLog(1, "200.检查开班:" + ex.Message);
                myShiftReturn.code = "400";
                myShiftReturn.msg = "200.检查开班内部处理错误";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "200.检查开班");

            return myShiftReturn;
        }

        /// <summary>
        /// 201.开班
        /// </summary>
        public BACKDATA doOpenShift(ShiftBiz info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "201.开班..." + info.storeid + "/" + info.posno);

            BACKDATA myBACKDATA = new BACKDATA();
            myBACKDATA.code = "100";
            myBACKDATA.msg = "成功";

            try
            {
                string SQL = "exec PROC_POS_DOOPENSHIFT '" + info.storeid + "'"
                   + ",'" + info.posno + "'"
                   + ",'" + info.userid + "'"
                   + "," + info.amt.ToString();
                DataTable dttran = myADO.query(SQL);
                myBACKDATA.code = dttran.Rows[0][0].ToString();
                myBACKDATA.msg = dttran.Rows[0][1].ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("201.开班:" + ex.Message);
                Log.doWriteLog(1, "201.开班:" + ex.Message);
                myBACKDATA.code = "400";
                myBACKDATA.msg = "201.开班内部处理错误";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "201.开班");

            return myBACKDATA;
        }

        /// <summary>
        /// 202.交班
        /// </summary>
        public BACKDATA doCloseShift(ShiftBiz info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "202.交班..." + info.storeid + "/" + info.posno);

            BACKDATA myBACKDATA = new BACKDATA();
            myBACKDATA.code = "100";
            myBACKDATA.msg = "成功";

            try
            {
                string SQL = "exec PROC_POS_DOCLOSESHIFT '" + info.storeid + "'"
                   + ",'" + info.posno + "'"
                   + ",'" + info.userid + "'";
                DataTable dttran = myADO.query(SQL);
                myBACKDATA.code = dttran.Rows[0][0].ToString();
                myBACKDATA.msg = dttran.Rows[0][1].ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("202.交班:" + ex.Message);
                Log.doWriteLog(1, "202.交班:" + ex.Message);
                myBACKDATA.code = "400";
                myBACKDATA.msg = "202.交班内部处理错误";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "202.交班");

            return myBACKDATA;
        }

        /// <summary>
        /// 203.借零
        /// </summary>
        public BACKDATA doPutMoney(ShiftBiz info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "203.借零..." + info.storeid + "/" + info.posno);

            BACKDATA myBACKDATA = new BACKDATA();
            myBACKDATA.code = "100";
            myBACKDATA.msg = "成功";

            try
            {
                string SQL = "exec PROC_POS_DOSETSHIFTBIZ '" + info.storeid + "'"
                   + ",'" + info.posno + "'"
                   + ",'" + info.userid + "'"
                   + ",1"
                   + "," + info.amt.ToString();
                DataTable dttran = myADO.query(SQL);
                myBACKDATA.code = dttran.Rows[0][0].ToString();
                myBACKDATA.msg = dttran.Rows[0][1].ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("203.借零:" + ex.Message);
                Log.doWriteLog(1, "203.借零:" + ex.Message);
                myBACKDATA.code = "400";
                myBACKDATA.msg = "203.借零内部处理错误";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "203.借零");

            return myBACKDATA;
        }

        /// <summary>
        /// 204.投库
        /// </summary>
        public BACKDATA doGutMoney(ShiftBiz info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "204.投库..." + info.storeid + "/" + info.posno);

            BACKDATA myBACKDATA = new BACKDATA();
            myBACKDATA.code = "100";
            myBACKDATA.msg = "成功";

            try
            {
                string SQL = "exec PROC_POS_DOSETSHIFTBIZ '" + info.storeid + "'"
                   + ",'" + info.posno + "'"
                   + ",'" + info.userid + "'"
                   + ",2"
                   + "," + info.amt.ToString();
                DataTable dttran = myADO.query(SQL);
                myBACKDATA.code = dttran.Rows[0][0].ToString();
                myBACKDATA.msg = dttran.Rows[0][1].ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("204.投库:" + ex.Message);
                Log.doWriteLog(1, "204.投库:" + ex.Message);
                myBACKDATA.code = "400";
                myBACKDATA.msg = "204.投库内部处理错误";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "204.投库");

            return myBACKDATA;
        }

        /// <summary>
        /// 205.班别查询
        /// </summary>
        public ShiftList doQueryShift(ShiftQuery info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "205.班别查询..." + info.storeid + "/" + info.posno);

            ShiftList myShiftList = new ShiftList();
            myShiftList.code = "100";
            myShiftList.msg = "成功";
            myShiftList.TCShiftList = new List<ShiftList.ShiftData>();
            try
            {
                string SQL = " select  ISNULL(b.fEmpName, a.fCashier) userid,fShift shiftno"
                 + " ,case fState when 1 then '未交班' when 2 then '已交班' end shiftstate"
                 + " ,grosalamt, discamt, saleamt, flowcount, paidinamt, paidoutamt"
                 + " ,convert(varchar(10), fBegDate, 120) begdate"
                 + " ,convert(varchar(10), fEndDate, 120) enddate"
                 + " from epos.dbo.Tc_shift a"
                 + " left join Ts_Employee b on a.fCashier = b.fEmpNo"
                 + " where a.Warehouseid='" + info.storeid + "'"
                 + " and a.fPosNo = '" + info.posno + "'"
                 + " and a.fAccDate='" + info.accdate + "'";
                if (info.shiftno.Length > 0)
                {
                    SQL = SQL + " and a.fShift = '"+info.shiftno+"'";
                }

                SQL = SQL + " order by a.fShift ";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    ShiftList.ShiftData mytranhead = new ShiftList.ShiftData();
                    mytranhead.userid =  dttranhead.Rows[m]["userid"].ToString();
                    mytranhead.shiftstate = dttranhead.Rows[m]["shiftstate"].ToString();
                    mytranhead.shiftno = dttranhead.Rows[m]["shiftno"].ToString();
                    mytranhead.grosalamt = decimal.Parse(dttranhead.Rows[m]["grosalamt"].ToString());
                    mytranhead.discamt = decimal.Parse(dttranhead.Rows[m]["discamt"].ToString());
                    mytranhead.saleamt = decimal.Parse(dttranhead.Rows[m]["saleamt"].ToString());
                    mytranhead.flowcount = int.Parse(dttranhead.Rows[m]["flowcount"].ToString());
                    mytranhead.paidinamt = decimal.Parse(dttranhead.Rows[m]["paidinamt"].ToString());
                    mytranhead.paidoutamt = decimal.Parse(dttranhead.Rows[m]["paidoutamt"].ToString());
                    mytranhead.begdate = dttranhead.Rows[m]["begdate"].ToString();
                    mytranhead.enddate = dttranhead.Rows[m]["enddate"].ToString();

                    mytranhead.ShiftPayList = new List<ShiftList.ShiftPay>();

                    string SQL2 = "select  ROW_NUMBER()over(order by posNo,flowno) as seq"
                      +"  , ISNULL(b.fPayScreenName, payWay) payWay,payAmt"
                      +"  from epos.dbo.pos_shift a"
                      +"  left join Ts_PosPayment b on a.payWay = b.fPayID"
                      +" where a.Warehouseid='" + info.storeid + "'"
                      +" and a.posNo = '" + info.posno + "'"
                      +" and a.flowno='"+ mytranhead.shiftno + "'"
                      +" order by 1";
                    DataTable dttrandtl = myADO.query(SQL2);
                    for (int i = 0; i < dttrandtl.Rows.Count; i++)
                    {
                        ShiftList.ShiftPay mytrandtl = new ShiftList.ShiftPay();
                        mytrandtl.lineno = int.Parse(dttrandtl.Rows[i]["seq"].ToString());
                        mytrandtl.payway = dttrandtl.Rows[i]["payWay"].ToString();
                        mytrandtl.payamt = decimal.Parse(dttrandtl.Rows[i]["payAmt"].ToString());

                        mytranhead.ShiftPayList.Add(mytrandtl);
                    }
                    //交易主表
                    myShiftList.TCShiftList.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("205.班别查询:" + ex.Message);
                Log.doWriteLog(1, "205.班别查询:" + ex.Message);
                myShiftList.code = "400";
                myShiftList.msg = "205.班别查询内部处理错误";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "205.班别查询");

            return myShiftList;
        }

        /// <summary>
        /// 206.日结
        /// </summary>
        public BACKDATA doEndDay(endday info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "206.日结..." + info.storeid + "/" + info.posno);

            BACKDATA myBACKDATA = new BACKDATA();
            myBACKDATA.code = "100";
            myBACKDATA.msg = "成功";

            try
            {
                string SQL = "exec PROC_POS_DOENDDAY '" + info.storeid + "'"
                   + ",'" + info.posno + "'"
                   + ",'" + info.userid + "'"
                   + ",'" + info.accdate + "'";
                DataTable dttran = myADO.query(SQL);
                myBACKDATA.code = dttran.Rows[0][0].ToString();
                myBACKDATA.msg = dttran.Rows[0][1].ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("206.日结:" + ex.Message);
                Log.doWriteLog(1, "206.日结:" + ex.Message);
                myBACKDATA.code = "400";
                myBACKDATA.msg = "206.日结内部处理错误";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "206.日结");

            return myBACKDATA;
        }

        /// <summary>
        /// 207.日结查询
        /// </summary>
        public endList doQueryDay(endday info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "207.日结查询..." + info.storeid + "/" + info.posno);

            endList myendList = new endList();
            myendList.code = "100";
            myendList.msg = "成功";
            myendList.endPayList = new List<endList.endPay>();
            try
            {
                int m = 0;
                string SQL = " select count(1) f, sum(grosalamt) grosalamt,sum(discamt) discamt,sum(saleamt)saleamt "
                 + " ,sum(flowcount) flowcount,sum(paidinamt) paidinamt,sum(paidoutamt) paidoutamt"
                 + " ,convert(varchar(10), min(fBegDate), 120) begdate"
                 + " ,convert(varchar(10), max(fEndDate), 120) enddate"
                 + " from epos.dbo.Tc_shift a"
                 + " where a.Warehouseid='" + info.storeid + "'"
                 + " and a.fPosNo = '" + info.posno + "'"
                 + " and a.fAccDate='" + info.accdate + "'";
                DataTable dttranhead = myADO.query(SQL);
                if (int.Parse(dttranhead.Rows[m]["f"].ToString())>0)
                {
                    myendList.grosalamt = decimal.Parse(dttranhead.Rows[m]["grosalamt"].ToString());
                    myendList.discamt = decimal.Parse(dttranhead.Rows[m]["discamt"].ToString());
                    myendList.saleamt = decimal.Parse(dttranhead.Rows[m]["saleamt"].ToString());
                    myendList.flowcount = int.Parse(dttranhead.Rows[m]["flowcount"].ToString());
                    myendList.paidinamt = decimal.Parse(dttranhead.Rows[m]["paidinamt"].ToString());
                    myendList.paidoutamt = decimal.Parse(dttranhead.Rows[m]["paidoutamt"].ToString());
                    myendList.begdate = dttranhead.Rows[m]["begdate"].ToString();
                    myendList.enddate = dttranhead.Rows[m]["enddate"].ToString();

                    string SQL2 = "select ISNULL(b.fPayScreenName, payWay) payWay,sum(payAmt)payAmt"
                      + "  from epos.dbo.pos_shift a"
                      + "  left join Ts_PosPayment b on a.payWay = b.fPayID"
                      + " where a.Warehouseid='" + info.storeid + "'"
                      + " and a.posNo = '" + info.posno + "'"
                      + " and a.AccDate='" + info.accdate + "'"
                      + " group by b.fPayScreenName, payWay"
                      + " order by 1";
                    DataTable dttrandtl = myADO.query(SQL2);
                    for (int i = 0; i < dttrandtl.Rows.Count; i++)
                    {
                        endList.endPay mytrandtl = new endList.endPay();
                        mytrandtl.lineno = i;
                        mytrandtl.payway = dttrandtl.Rows[i]["payWay"].ToString();
                        mytrandtl.payamt = decimal.Parse(dttrandtl.Rows[i]["payAmt"].ToString());

                        myendList.endPayList.Add(mytrandtl);
                    }
                    //交易主表
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("207.日结查询:" + ex.Message);
                Log.doWriteLog(1, "207.日结查询:" + ex.Message);
                myendList.code = "400";
                myendList.msg = "207.日结查询内部处理错误";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "207.日结查询");

            return myendList;
        }

        /// <summary>
        /// 交易上传
        /// </summary>
        public OrdDataInfo docreateOrder(OrdData info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "103.订单信息..." + info.storeId +"/"+info.posNo+ "/" + info.totalPrice);

            string sOrdId = string.Empty;

            OrdDataInfo myOrdDataInfo = new OrdDataInfo();
            myOrdDataInfo.code = "100";
            try
            {
                string sShiftFlowNo = info.posNo + DateTime.Now.ToString("yyyyMMdd") + "0001";

                string SQL = "exec PROC_POS_DOCHECKSHIFT '" + info.storeId + "'"
                   + ",'" + info.posNo + "'"
                   + ",'" + info.cashierId + "'";
                DataTable dttran = myADO.query(SQL);
                if (dttran.Rows[0][0].ToString().Equals("100"))
                {
                    myOrdDataInfo.code = "201";
                    myOrdDataInfo.msg = "201.请先开班";
                    return myOrdDataInfo;
                }
                sShiftFlowNo = dttran.Rows[0][5].ToString(); //当前班别号

                SQL = "declare @pNo varchar(20),@pId varchar(20)"
                   + "  exec proc_getbillNo 6,@pId output, @pNo output"
                   + "  select @pNo";
                DataTable dtBillNo = myADO.query(SQL);
                sOrdId = dtBillNo.Rows[0][0].ToString();
                myADO.SQLList.Clear();

                string sAccDate = DateTime.Now.ToString("yyyy-MM-dd");

                //解析订单
                string productInfoJson = info.productInfoJson;
                List<OrdData.OrdItem> myOrdItem = JsonConvert.DeserializeObject<List<OrdData.OrdItem>>(productInfoJson);//反序列化
                for (int i = 0; i < myOrdItem.Count; i++)
                {
                    //Console.WriteLine(myOrdItem[i].pluName);
                    SQL = "insert into epos.dbo.pos_tranflow(WarehouseID,PosNo,flowno,itemseq,pluno"
                     + " ,unitPrice,salePrice,avPrice,saleQty,DiscAmt,beforeDiscAmt,afterDiscAmt"
                     + " ,isDirectDisc,saleAmt,SuitNo,FoodType"
                     + " ,sellWay,operId,saleMan,operDate,Uploadflag,ShiftFlowNo"
                     + " ,AccDate,DeskProperty,uniqueID,bcatno,scatno"
                     + " ,ChangePriceFlag,ChangePriceAmt,saleManName,TasteMemo"
                     + " ,DiscFlag,MemberPoint,FeedList,TCAmt,BaseAmt,MMDiscAmt"
                     + " ,tasteTotalAmt,ServiceAmt,sign,TaxID,TaxAmt,custId"
                     + " ,pluname,barcode,ulFlag,fClassStNo,fCreateDate)"
                     + " values('" + info.storeId + "','" + info.posNo + "','" + sOrdId + "',"
                     + myOrdItem[i].flineno.ToString()
                     + ",'" + myOrdItem[i].customerCode + "'"
                     + "," + myOrdItem[i].originalPrice.ToString()
                     + "," + myOrdItem[i].pluPrice.ToString()
                     + ",0," + myOrdItem[i].qty.ToString()
                     + "," + myOrdItem[i].promBeforeDiscAmt.ToString() + "+" + myOrdItem[i].promAfterDiscAmt.ToString()
                     + "," + myOrdItem[i].promBeforeDiscAmt.ToString()
                     + "," + myOrdItem[i].promAfterDiscAmt.ToString()
                     + ",'" + myOrdItem[i].promno.ToString() + "'"
                     + "," + myOrdItem[i].saleAmt.ToString()
                     + ",'','" + myOrdItem[i].type.ToString() + "','A','" + info.cashierId + "','" + info.saleman + "','" + info.systemdate + "','N','" + sShiftFlowNo + "'"
                     + ",'" + sAccDate + "','00',0,'" + myOrdItem[i].materialClassIdLarge.ToString() + "','" + myOrdItem[i].materialClassIdMid.ToString() + "'"
                     + ",0,0,'" + info.posNo + "',''"
                     + ",'N',0,'',0,0,0"
                     + ",0,0,'',0,0,'001'"
                     + ",'" + myOrdItem[i].pluName + "','" + myOrdItem[i].erpCode + "','0','" + myOrdItem[i].materialClassIdSmall + "',getdate()"
                     + ")";
                    myADO.SQLList.Add(SQL);
                }

                //解析礼券
                if (info.GiveCouponVO.Length > 0)
                {
                    string useTickList = info.GiveCouponVO;
                    List<OrdData.TicketData> myTicketData = JsonConvert.DeserializeObject<List<OrdData.TicketData>>(useTickList);//反序列化
                    for (int i = 0; i < myTicketData.Count; i++)
                    {
                        SQL = "insert into epos.dbo.pos_tranticket(WarehouseID,PosNo,flowno,itemseq"
                         + " ,fbatchno,fnum,operDate,sellWay)"
                         + " values('" + info.storeId + "','" + info.posNo + "','" + sOrdId + "',"
                         + myTicketData[i].flineno.ToString()
                         + ",'" + myTicketData[i].fbatchno + "'"
                         + "," + myTicketData[i].fnum.ToString()
                         + ",'" + info.systemdate + "','A')";
                        myADO.SQLList.Add(SQL);
                    }
                }

                SQL = "insert into epos.dbo.pos_tranhead(Accdate,Warehouseid,Flowno,Sellway"
                 + " ,GrosalAMT,DiscAMT,SaleAmt,OverAmt,ChgAmt,beforeDiscAmt,afterDiscAmt"
                 + "  ,operId,OperDate,saleMan,isInRoom,Deskproperty"
                 + "  ,CustNumber,CustManNumber,CustWoManNumber,CustChildNumber,CustWoMan,CustZWoman,CustYWoman,CustOMan,CustOWoman"
                 + "  ,ShiftFlowNo,uploadFlag,custId,MMDiscAmt,AccFlag,PosNo"
                 + "  ,tasteAmt,vipNo,vippoint,vippointToMoney,HaveServiceAmt,TaxAmt,fCreateDate)"
                 + " values('" + sAccDate + "','" + info.storeId + "','" + sOrdId + "','A'"
                 + " ," + info.totalPrice.ToString() + "+" + info.totalDiscount.ToString()
                 + "," + info.totalDiscount.ToString()
                 + "," + info.totalPrice.ToString()
                 + ",0,0,0,0"
                 + ",'" + info.cashierId + "','" + info.systemdate + "','" + info.saleman + "',"+info.posOrderType + ",'00'"
                 + ",1,1,0,0,0,0,0,0,0"
                 + ",'" + sShiftFlowNo + "','N','101',0,'0','" + info.posNo + "'"
                 + ",0,'" + info.memberno + "',0,0,0,0,getdate()"
                 + ")";
                myADO.SQLList.Add(SQL);

                bool IsOk = false;
                string sError = string.Empty;
                myADO.doSave(out IsOk, out sError);

                //返回
                OrdDataInfo.Content myContent = new OrdDataInfo.Content();
                myContent.payPrice = 0;
                myContent.orderId = sOrdId;
                
                if (!IsOk)
                {
                    myOrdDataInfo.code = "100";
                    myContent.payPrice = 0;
                    myContent.orderId = "";
                }
                myOrdDataInfo.msg = sError;
                myOrdDataInfo.content = myContent;
            }
            catch (Exception ex)
            {
                Console.WriteLine("103.交易上传出错:" + ex.Message);
                Log.doWriteLog(1, "103.交易上传出错:" + ex.Message);
                myOrdDataInfo.code = "400";
                myOrdDataInfo.msg = "103.交易上传出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "103.交易上传处理完毕," + sOrdId);

            return myOrdDataInfo;
        }

        /// <summary>
        /// 支付信息
        /// </summary>
        public OrdPayInfo doPayFace(OrdPay info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "104.支付信息..." + info.orderId + "/" + info.payPrice.ToString());

            OrdPayInfo myOrdPayInfo = new OrdPayInfo();
            myOrdPayInfo.code = "100";
            myOrdPayInfo.msg = "成功";

            OrdPayInfo.Content myContent = new OrdPayInfo.Content();

            try
            {
                string SQL = "exec PROC_POS_DOSETTRANPAY '" + info.storeId + "'"
                   + ",'" + info.orderId + "'"
                   + ",'" + info.payChannel + "'"
                   + ",'" + info.code + "'"
                   + "," + info.payPrice.ToString();
                DataTable dttran = myADO.query(SQL);
                myOrdPayInfo.code = dttran.Rows[0][0].ToString();
                myOrdPayInfo.msg = dttran.Rows[0][1].ToString();
                myContent.surplus_amount = decimal.Parse(dttran.Rows[0][2].ToString());
                myContent.give_change_amount = decimal.Parse(dttran.Rows[0][3].ToString());
                myContent.total_amount = decimal.Parse(dttran.Rows[0][4].ToString());
                myContent.invoice_amount = decimal.Parse(dttran.Rows[0][5].ToString());
                myContent.orderStatus = int.Parse(dttran.Rows[0][6].ToString());

                myOrdPayInfo.content = myContent;
            }
            catch (Exception ex)
            {
                Console.WriteLine("104.支付信息处理出错:" + ex.Message);
                Log.doWriteLog(1, "104.支付信息处理出错:" + ex.Message);
                myOrdPayInfo.code = "400";
                myOrdPayInfo.msg = "104.支付信息处理出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "104.支付信息处理完毕");

            return myOrdPayInfo;
        }
        
        /// <summary>
        /// 订单查询
        /// </summary>
        public TranData dogetOrderInfoList(OrdQry info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "105.订单查询..." + info.storeId + "/" + info.placeStartDate+"/"+info.placeEndDate);

            TranData myTranData = new TranData();
            myTranData.code = "100";
            myTranData.msg = "成功";

            myTranData.tranhead = new List<TranData.Ttranhead>();

            try
            {
                string SQL = "select id,Flowno"
                  + " ,case Sellway when 'A' then '销售' else '退货' end Sellway"
                  + " ,GrosalAMT, DiscAMT, SaleAmt, OverAmt, ChgAmt, beforeDiscAmt, afterDiscAmt"
                  + " , operId, OperDate, saleMan, isInRoom,vipNo,b.FMEMNAME "
                  + " ,case isInRoom when 1 then '堂食' else '外带' end isInRoom "
                  + " from epos.dbo.pos_tranhead a"
                  + " left join member.dbo.Ts_memberBase b  on b.fCustId=101 and b.fMemberNo=a.vipNo"
                  + " where Warehouseid='" + info.storeId + "'"
                  + " and convert(datetime,OperDate) between convert(datetime,'" + info.placeStartDate + "')"
                  + " and convert(datetime,'" + info.placeEndDate + "')"
                  + " and Sellway in ('A','B')"
                  + " order by flowno";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    TranData.Ttranhead mytranhead = new TranData.Ttranhead();
                    mytranhead.orderid = int.Parse(dttranhead.Rows[m]["id"].ToString());
                    mytranhead.orderno = dttranhead.Rows[m]["Flowno"].ToString();
                    mytranhead.sellway = dttranhead.Rows[m]["Sellway"].ToString();
                    mytranhead.orderdate = dttranhead.Rows[m]["OperDate"].ToString();
                    mytranhead.vipno = dttranhead.Rows[m]["vipNo"].ToString();
                    mytranhead.vipname = dttranhead.Rows[m]["FMEMNAME"].ToString();
                    mytranhead.ordertype = dttranhead.Rows[m]["isInRoom"].ToString();
                    mytranhead.orderAmt = decimal.Parse(dttranhead.Rows[m]["GrosalAMT"].ToString());
                    mytranhead.discAmt = dttranhead.Rows[m]["DiscAMT"].ToString();
                    mytranhead.saleAmt = dttranhead.Rows[m]["SaleAmt"].ToString();
                    
                    mytranhead.trandtl = new List<TranData.Ttrandtl>();

                    string SQL2 = "select itemseq,pluno,pluname,salePrice,DiscAmt,convert(int,saleQty) saleQty,saleAmt,TasteMemo"
                        + " from epos.dbo.pos_tranflow"
                        + " where Warehouseid='" + info.storeId + "'"
                        + " and flowno ='" + dttranhead.Rows[m]["Flowno"].ToString() + "'"
                        + " order by id";
                    DataTable dttrandtl = myADO.query(SQL2);
                    for (int i = 0; i < dttrandtl.Rows.Count; i++)
                    {
                        TranData.Ttrandtl mytrandtl = new TranData.Ttrandtl();
                        mytrandtl.line = int.Parse(dttrandtl.Rows[i]["itemseq"].ToString());
                        mytrandtl.pluno = dttrandtl.Rows[i]["pluno"].ToString();
                        mytrandtl.pluname = dttrandtl.Rows[i]["pluname"].ToString();
                        mytrandtl.pluprice = decimal.Parse(dttrandtl.Rows[i]["salePrice"].ToString());
                        mytrandtl.qty = int.Parse(dttrandtl.Rows[i]["saleQty"].ToString());
                        mytrandtl.discount = decimal.Parse(dttrandtl.Rows[i]["DiscAmt"].ToString());
                        mytrandtl.amt = decimal.Parse(dttrandtl.Rows[i]["saleAmt"].ToString());
                        mytrandtl.tasklist = dttrandtl.Rows[i]["TasteMemo"].ToString();

                        mytranhead.trandtl.Add(mytrandtl);
                    }
                    //交易主表
                    myTranData.tranhead.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("105.订单查询出错:" + ex.Message);
                Log.doWriteLog(1, "105.订单查询出错:" + ex.Message);
                myTranData.code = "400";
                myTranData.msg = "105.订单查询出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "105.订单查询处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 订单退货
        /// </summary>
        public BACKDATA dopayRefund(OrdReturn info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "106.订单退货..." + info.orderId);

            BACKDATA myOrdReturnData = new BACKDATA();
            myOrdReturnData.code = "100";
            myOrdReturnData.msg = "成功";

            try
            {
                string SQL = "exec PROC_POS_DOSETTRANRETURN '" + info.storeId + "'"
                   + ",'" + info.orderId + "'";
                DataTable dttran = myADO.query(SQL);
                myOrdReturnData.code = dttran.Rows[0][0].ToString();
                myOrdReturnData.msg = dttran.Rows[0][1].ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("106.订单退货出错:" + ex.Message);
                Log.doWriteLog(1, "106.订单退货出错:" + ex.Message);
                myOrdReturnData.code = "400";
                myOrdReturnData.msg = "106.订单退货出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "106.订单退货处理完毕");

            return myOrdReturnData;
        }

        /// <summary>
        /// 外卖订单
        /// </summary>
        public WMOrd dogetWMOrder(WMOrdQry info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "107.外卖订单..." + info.storeId + "/" + info.orderId.ToString());

            WMOrd myTranData = new WMOrd();
            myTranData.code = 100;
            myTranData.msg = "成功";

            myTranData.tranhead = new List<WMtranhead>();

            try
            {
                string SQL = "select top 5 id,channelSheetno,channelKeyword,billtype"
                 + " , returnOrderSn, totalSaleValue, totalDiscValue"
                 + " ,startDeliveryTime, convert(varchar(20),endDeliveryTime,120) endDeliveryTime, status, orgCode"
                 + ", orderTime, receiverName, receiverGender, receiverMobile"
                 + ", receiverAddress, note, receiverType"
                 + " from epos.dbo.takeaway_order_head"
                 + "  where id>" + info.orderId.ToString()
                 + "  and orgCode='" + info.storeId + "'"
                 + " order by id";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    WMtranhead mytranhead = new WMtranhead();
                    mytranhead.orderid = int.Parse(dttranhead.Rows[m]["id"].ToString());
                    mytranhead.orderno = dttranhead.Rows[m]["channelSheetno"].ToString();
                    mytranhead.orderdate = dttranhead.Rows[m]["orderTime"].ToString();
                    mytranhead.orderstye = dttranhead.Rows[m]["channelKeyword"].ToString();
                    mytranhead.vipno = dttranhead.Rows[m]["receiverGender"].ToString();
                    mytranhead.vipname = dttranhead.Rows[m]["receiverName"].ToString();
                    mytranhead.telno = dttranhead.Rows[m]["receiverMobile"].ToString();
                    mytranhead.orderAmt = decimal.Parse(dttranhead.Rows[m]["totalSaleValue"].ToString());
                    mytranhead.ordertype = dttranhead.Rows[m]["receiverType"].ToString();
                    mytranhead.ordertime = dttranhead.Rows[m]["endDeliveryTime"].ToString();
                    mytranhead.address = dttranhead.Rows[m]["receiverAddress"].ToString();
                    mytranhead.memo = dttranhead.Rows[m]["note"].ToString();
                    mytranhead.orderstate = int.Parse(dttranhead.Rows[m]["status"].ToString());
                    mytranhead.trandtl = new List<WMtrandtl>();

                    string SQL2 = "select channelSheetno,seq,itemCode,barcode,name,qriginalPrice,salePrice"
                      + " , discValue, bcatno, qty, money"
                      + " from epos.dbo.takeaway_order_detail"
                      + " where channelSheetno='" + dttranhead.Rows[m]["channelSheetno"].ToString() + "'"
                      + " order by id";
                    DataTable dttrandtl = myADO.query(SQL2);
                    for (int i = 0; i < dttrandtl.Rows.Count; i++)
                    {
                        WMtrandtl mytrandtl = new WMtrandtl();
                        mytrandtl.line = int.Parse(dttrandtl.Rows[i]["seq"].ToString());
                        mytrandtl.pluno = dttrandtl.Rows[i]["barcode"].ToString();
                        mytrandtl.pluname = dttrandtl.Rows[i]["name"].ToString();
                        mytrandtl.pluprice = decimal.Parse(dttrandtl.Rows[i]["salePrice"].ToString());
                        mytrandtl.qty = int.Parse(dttrandtl.Rows[i]["qty"].ToString());
                        mytrandtl.amt = decimal.Parse(dttrandtl.Rows[i]["money"].ToString());
                        mytrandtl.tasklist = dttrandtl.Rows[i]["bcatno"].ToString();

                        mytranhead.trandtl.Add(mytrandtl);
                    }

                    //交易主表
                    myTranData.tranhead.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("107.外卖订单出错:" + ex.Message);
                Log.doWriteLog(1, "107.外卖订单出错:" + ex.Message);
                myTranData.code = 400;
                myTranData.msg = "107.外卖订单处理出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "107.外卖订单处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 会员登陆
        /// </summary>
        public MemberInfo doMemberLogin(MemberQry info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "108.会员登陆..." + info.memberNo);

            MemberInfo myMemberInfo = new MemberInfo();
            myMemberInfo.code = "100";
            myMemberInfo.msg = "成功";

            MemberInfo.Content myContent = new MemberInfo.Content();
            myMemberInfo.content = myContent;

            try
            {
                //1.检查当前单号状态
                string SQL = "SELECT FMEMBERNO,ISNULL(FMEMNAME,FWXNO) FMEMNAME,FLEVELNAME,FMEMSTATUS"
                 + ", CASE FLEVELSTYLE WHEN 1 THEN '会员折扣' WHEN 2 THEN '会员特价' END FTYPENAME"
                 + ", FLEVELSTYLE,FDISCOUNT, FENABLEPOINT"
                 + "  FROM Member.dbo.TS_MEMBERBASE A,Member.dbo.TS_MEMBERLEVEL B"
                 + "  WHERE A.FCUSTID = 101"
                 + "    AND A.FCUSTID = B.FCUSTID"
                 + "    AND A.FLEVELNO = B.FLEVELNO"
                 + "    AND((FMEMBERNO = '" + info.memberNo + "' OR FMOBILE = '" + info.memberNo + "'))";
                DataTable dttran = myADO.query(SQL);
                if (dttran is null || dttran.Rows.Count == 0)
                {
                    myMemberInfo.code = "101";
                    myMemberInfo.msg = "会员编号不正确";
                }
                else
                {
                    if (!dttran.Rows[0]["FMEMSTATUS"].ToString().Equals("1"))
                    {
                        myMemberInfo.code = "102";
                        myMemberInfo.msg = "该会员不允许登陆";
                    }
                    else
                    {
                        myContent.FMEMBERNO = dttran.Rows[0]["FMEMBERNO"].ToString();
                        myContent.FMEMNAME = dttran.Rows[0]["FMEMNAME"].ToString();
                        myContent.FLEVELNAME = dttran.Rows[0]["FLEVELNAME"].ToString();
                        myContent.FLEVELSTYLE = int.Parse(dttran.Rows[0]["FLEVELSTYLE"].ToString());
                        myContent.FTYPENAME = dttran.Rows[0]["FTYPENAME"].ToString();
                        myContent.FDISCOUNT = Convert.ToDecimal(dttran.Rows[0]["FDISCOUNT"].ToString());
                        myContent.FENABLEPOINT = Convert.ToDecimal(dttran.Rows[0]["FENABLEPOINT"].ToString());
                    }

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("108.会员登陆出错:" + ex.Message);
                Log.doWriteLog(1, "108.会员登陆出错:" + ex.Message);
                myMemberInfo.code = "400";
                myMemberInfo.msg = "108.会员登陆出错";
            }

            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "108.会员登陆处理完毕");

            return myMemberInfo;
        }

        /// <summary>
        /// 获取会员礼券列表(批次)
        /// </summary>
        public TICKETLIST doGetTicketList(MemberQry info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "109.会员礼券列表..." + info.storeId + "/" + info.memberNo);

            TICKETLIST myTICKETLIST = new TICKETLIST();
            myTICKETLIST.code = 100;
            myTICKETLIST.msg = "成功";

            myTICKETLIST.ticketList = new List<TICKETLIST.MemberTicket>();

            try
            {
                string SQL = "SELECT A.FPUBLISHNOTE FTICKETCATNAME,FBATCHNO"
                  + " ,CONVERT(VARCHAR(10),FBEGDATE,120)FBEGDATE"
                  + " ,CONVERT(VARCHAR(10),FENDDATE,120)FENDDATE"
                  + " ,CASE FCALFIELD WHEN 1 THEN '消费' ELSE '购买' END + CONVERT(VARCHAR(10), CONVERT(INT, FCALMONEY)) + CASE FCALFIELD WHEN 1 THEN '元' ELSE '个' END + CASE FCALTYPE WHEN 1 THEN '折让' ELSE '折扣' END + CONVERT(VARCHAR(10), FFULLMONEY) FTITLE"
                  + " , FNUM,FTICKETTYPE,FCALFIELD,FCALMONEY,FCALTYPE,FFULLMONEY,FUSELIMIT"
                  + " FROM Member.dbo.TS_TICKETCAT B"
                  + ",(SELECT a.FCUSTID,a.FTICKETCATNO,a.FBATCHNO,c.FPUBLISHNOTE,a.FBEGDATE,a.FENDDATE, COUNT(1) FNUM"
                  + "   FROM Member.dbo.TS_TICKET a,Member.dbo.TC_TICKETPUBLISH c"
                  + "  WHERE a.FCUSTID = 101"
                  + "    AND FMEMBERNO = '" + info.memberNo + "'"
                  + "    AND CONVERT(VARCHAR(10), GETDATE(), 120) BETWEEN a.FBEGDATE AND a.FENDDATE"
                  + "    AND a.FSTATUS = 1"
                  + "    AND a.FCUSTID=c.FCUSTID"
                  + "    AND a.FBATCHNO = c.FBATCHNO"
                  + "    GROUP BY a.FCUSTID,a.FTICKETCATNO,a.FBATCHNO,c.FPUBLISHNOTE,a.FBEGDATE,a.FENDDATE) A"
                  + "     WHERE A.FCUSTID = B.FCUSTID"
                  + "  AND A.FTICKETCATNO = B.FTICKETCATNO";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    TICKETLIST.MemberTicket mytranhead = new TICKETLIST.MemberTicket();
                    mytranhead.FTICKETCATNAME = dttranhead.Rows[m]["FTICKETCATNAME"].ToString();
                    mytranhead.FBATCHNO = dttranhead.Rows[m]["FBATCHNO"].ToString();
                    mytranhead.FBEGDATE = dttranhead.Rows[m]["FBEGDATE"].ToString();
                    mytranhead.FENDDATE = dttranhead.Rows[m]["FENDDATE"].ToString();
                    mytranhead.FTITLE = dttranhead.Rows[m]["FTITLE"].ToString();
                    mytranhead.FNUM = int.Parse(dttranhead.Rows[m]["FNUM"].ToString());
                    mytranhead.FTICKETTYPE = int.Parse(dttranhead.Rows[m]["FTICKETTYPE"].ToString());
                    mytranhead.FCALFIELD = int.Parse(dttranhead.Rows[m]["FCALFIELD"].ToString());
                    mytranhead.FCALMONEY = decimal.Parse(dttranhead.Rows[m]["FCALMONEY"].ToString());
                    mytranhead.FCALTYPE = int.Parse(dttranhead.Rows[m]["FCALTYPE"].ToString());
                    mytranhead.FFULLMONEY = decimal.Parse(dttranhead.Rows[m]["FFULLMONEY"].ToString());
                    mytranhead.FUSELIMIT = int.Parse(dttranhead.Rows[m]["FUSELIMIT"].ToString());

                    //兑换商品
                    mytranhead.ItemList = new List<TICKETLIST.TicketItem>();

                    string SQL2 = "  SELECT FCATSCORE,B.FITEMNO"
                      + " FROM Member.dbo.TC_TICKETPUBLISH A"
                      + " LEFT JOIN Member.dbo.TC_TICKETPUBLISH_ITEM B ON A.FCUSTID = B.FCUSTID AND A.FBATCHNO = B.FBATCHNO"
                      + " WHERE A.FCUSTID = 101"
                      + " AND A.FBATCHNO = '" + dttranhead.Rows[m]["FBATCHNO"].ToString() + "'";
                    DataTable dttrandtl = myADO.query(SQL2);
                    for (int i = 0; i < dttrandtl.Rows.Count; i++)
                    {
                        TICKETLIST.TicketItem mytrandtl = new TICKETLIST.TicketItem();
                        mytrandtl.FCATSCORE = int.Parse(dttrandtl.Rows[i]["FCATSCORE"].ToString());
                        mytrandtl.FITEMNO = dttrandtl.Rows[i]["FITEMNO"].ToString();

                        //礼券使用商品列表
                        mytranhead.ItemList.Add(mytrandtl);
                    }

                    //交易主表
                    myTICKETLIST.ticketList.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("109.会员礼券列表出错:" + ex.Message);
                Log.doWriteLog(1, "109.会员礼券列表出错:" + ex.Message);
                myTICKETLIST.code = 400;
                myTICKETLIST.msg = "109.会员礼券列表出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "109.会员礼券列表");

            return myTICKETLIST;
        }

        /// <summary>
        /// 会员注册
        /// </summary>
        public BACKDATA doRegMember(NewMember info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "110.会员注册..." + info.fmobile);

            BACKDATA myData = new BACKDATA();

            try
            {
                string SQL = "exec Member.dbo.PROC_MEMBER_NEW 101"
                  + ",'" + info.storeId + "'"
                  + ",'" + info.userId + "'"
                  + ",'" + info.memberName + "'"
                  + ",'" + info.fmobile + "'"
                  + "," + info.fsex.ToString()
                  + ",'" + info.fbirthday + "'";
                DataTable dttran = myADO.query(SQL);
                myData.code = dttran.Rows[0][0].ToString();
                myData.msg = dttran.Rows[0][1].ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("109.会员注册出错:" + ex.Message);
                Log.doWriteLog(1, "109.会员注册出错:" + ex.Message);
                myData.code = "400";
                myData.msg = "服务端出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "109.会员注册处理完毕");

            return myData;
        }

        /// <summary>
        /// 获取兑换优惠券列表
        /// </summary>
        public ExchangeList doGetExchangeList(MemberQry info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "111.获取兑换优惠券列表..." + info.storeId + "/" + info.memberNo);

            ExchangeList myTICKETLIST = new ExchangeList();
            myTICKETLIST.code = 100;
            myTICKETLIST.msg = "成功";

            myTICKETLIST.ExchangeData = new List<ExchangeList.ExchangeItem>();
            try
            {
                string SQL = "exec Member.dbo.PROC_TICKET_GETEXCHANGELIST 101 "
                   + ",'" + info.storeId + "'"
                   + ",'" + info.memberNo + "'";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    ExchangeList.ExchangeItem mytranhead = new ExchangeList.ExchangeItem();
                    mytranhead.fpromno = dttranhead.Rows[m]["fpromno"].ToString();
                    mytranhead.fpromname = dttranhead.Rows[m]["fpromname"].ToString();
                    mytranhead.fbegdate = dttranhead.Rows[m]["fbegdate"].ToString();
                    mytranhead.fenddate = dttranhead.Rows[m]["fenddate"].ToString();
                    mytranhead.fbatchno = dttranhead.Rows[m]["fbatchno"].ToString();
                    mytranhead.fticketcatno = dttranhead.Rows[m]["fticketcatno"].ToString();
                    mytranhead.fticketcatname = dttranhead.Rows[m]["fticketcatname"].ToString();
                    mytranhead.ftickettype = dttranhead.Rows[m]["ftickettype"].ToString();
                    mytranhead.ftitle = dttranhead.Rows[m]["ftitle"].ToString();
                    mytranhead.fpoint = int.Parse(dttranhead.Rows[m]["fpoint"].ToString());
                    mytranhead.fqty = int.Parse(dttranhead.Rows[m]["fqty"].ToString());

                    //交易主表
                    myTICKETLIST.ExchangeData.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("111.获取兑换列表出错:" + ex.Message);
                Log.doWriteLog(1, "111.获取兑换列表出错:" + ex.Message);
                myTICKETLIST.code = 400;
                myTICKETLIST.msg = "服务端出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "111.获取兑换优惠券列表");

            return myTICKETLIST;
        }

        /// <summary>
        /// 提交兑换优惠券列表
        /// </summary>
        public BACKDATA doSetExchangeList(ExchangeTicket info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "112.提交兑换优惠券列表..." + info.memberNo);

            BACKDATA myData = new BACKDATA();

            //
            try
            {
                string SQL = "exec Member.dbo.PROC_TICKET_SETEXCHANGELIST 101"
                  + ",'" + info.storeId + "'"
                  + ",'" + info.userId + "'"
                  + ",'" + info.memberNo + "'"
                  + ",'" + info.ticketList + "'";
                DataTable dttran = myADO.query(SQL);
                myData.code = dttran.Rows[0][0].ToString();
                myData.msg = dttran.Rows[0][1].ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("112.提交兑换列表出错:" + ex.Message);
                Log.doWriteLog(1,"112.提交兑换列表出错:" + ex.Message);
                myData.code = "400";
                myData.msg = "服务端出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "112.提交兑换优惠券列表");

            return myData;
        }

        /// <summary>
        /// 获取会员礼券列表(号码)
        /// </summary>
        public TICKETINFO doGetTicketInfo(MemberQry info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "109.会员礼券列表..." + info.storeId + "/" + info.memberNo);

            TICKETINFO myTICKETLIST = new TICKETINFO();
            myTICKETLIST.code = 100;
            myTICKETLIST.msg = "成功";

            myTICKETLIST.ticketList = new List<TICKETINFO.MemberTicket>();

            try
            {
                string SQL = "SELECT A.FTICKETNO,A.FPUBLISHNOTE FTICKETCATNAME,FBATCHNO"
                  + " ,CONVERT(VARCHAR(10),FBEGDATE,120)FBEGDATE"
                  + " ,CONVERT(VARCHAR(10),FENDDATE,120)FENDDATE"
                  + " ,CASE FCALFIELD WHEN 1 THEN '消费' ELSE '购买' END + CONVERT(VARCHAR(10), CONVERT(INT, FCALMONEY)) + CASE FCALFIELD WHEN 1 THEN '元' ELSE '个' END + CASE FCALTYPE WHEN 1 THEN '折让' ELSE '折扣' END + CONVERT(VARCHAR(10), FFULLMONEY) FTITLE"
                  + " , FNUM,FTICKETTYPE,FCALFIELD,FCALMONEY,FCALTYPE,FFULLMONEY,FUSELIMIT"
                  + " FROM Member.dbo.TS_TICKETCAT B"
                  + ",(SELECT a.FCUSTID,a.FTICKETNO,a.FTICKETCATNO,a.FBATCHNO,c.FPUBLISHNOTE,a.FBEGDATE,a.FENDDATE, 1 FNUM"
                  + "   FROM Member.dbo.TS_TICKET a,Member.dbo.TC_TICKETPUBLISH c"
                  + "  WHERE a.FCUSTID = 101"
                  + "    AND FMEMBERNO = '" + info.memberNo + "'"
                  + "    AND CONVERT(VARCHAR(10), GETDATE(), 120) BETWEEN a.FBEGDATE AND a.FENDDATE"
                  + "    AND a.FSTATUS = 1"
                  + "    AND a.FCUSTID=c.FCUSTID"
                  + "    AND a.FBATCHNO = c.FBATCHNO) A"
                  + "    WHERE A.FCUSTID = B.FCUSTID"
                  + "  AND A.FTICKETCATNO = B.FTICKETCATNO";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    TICKETINFO.MemberTicket mytranhead = new TICKETINFO.MemberTicket();
                    mytranhead.FTICKETNO = dttranhead.Rows[m]["FTICKETNO"].ToString();
                    mytranhead.FTICKETCATNAME = dttranhead.Rows[m]["FTICKETCATNAME"].ToString();
                    mytranhead.FBATCHNO = dttranhead.Rows[m]["FBATCHNO"].ToString();
                    mytranhead.FBEGDATE = dttranhead.Rows[m]["FBEGDATE"].ToString();
                    mytranhead.FENDDATE = dttranhead.Rows[m]["FENDDATE"].ToString();
                    mytranhead.FTITLE = dttranhead.Rows[m]["FTITLE"].ToString();
                    mytranhead.FNUM = int.Parse(dttranhead.Rows[m]["FNUM"].ToString());
                    mytranhead.FTICKETTYPE = int.Parse(dttranhead.Rows[m]["FTICKETTYPE"].ToString());
                    mytranhead.FCALFIELD = int.Parse(dttranhead.Rows[m]["FCALFIELD"].ToString());
                    mytranhead.FCALMONEY = decimal.Parse(dttranhead.Rows[m]["FCALMONEY"].ToString());
                    mytranhead.FCALTYPE = int.Parse(dttranhead.Rows[m]["FCALTYPE"].ToString());
                    mytranhead.FFULLMONEY = decimal.Parse(dttranhead.Rows[m]["FFULLMONEY"].ToString());
                    mytranhead.FUSELIMIT = int.Parse(dttranhead.Rows[m]["FUSELIMIT"].ToString());

                    //兑换商品
                    mytranhead.ItemList = new List<TICKETINFO.TicketItem>();

                    string SQL2 = "  SELECT FCATSCORE,B.FITEMNO"
                      + " FROM Member.dbo.TC_TICKETPUBLISH A"
                      + " LEFT JOIN Member.dbo.TC_TICKETPUBLISH_ITEM B ON A.FCUSTID = B.FCUSTID AND A.FBATCHNO = B.FBATCHNO"
                      + " WHERE A.FCUSTID = 101"
                      + " AND A.FBATCHNO = '" + dttranhead.Rows[m]["FBATCHNO"].ToString() + "'";
                    DataTable dttrandtl = myADO.query(SQL2);
                    for (int i = 0; i < dttrandtl.Rows.Count; i++)
                    {
                        TICKETINFO.TicketItem mytrandtl = new TICKETINFO.TicketItem();
                        mytrandtl.FCATSCORE = int.Parse(dttrandtl.Rows[i]["FCATSCORE"].ToString());
                        mytrandtl.FITEMNO = dttrandtl.Rows[i]["FITEMNO"].ToString();

                        //礼券使用商品列表
                        mytranhead.ItemList.Add(mytrandtl);
                    }

                    //交易主表
                    myTICKETLIST.ticketList.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("113.会员礼券列表出错:" + ex.Message);
                Log.doWriteLog(1, "113.会员礼券列表出错:" + ex.Message);
                myTICKETLIST.code = 400;
                myTICKETLIST.msg = "113.会员礼券列表出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "113.会员礼券列表");

            return myTICKETLIST;
        }

        /// <summary>
        /// 服饰--商品分类
        /// </summary>
        public padclass dogetCatList(padversion info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "301.服饰-商品分类..." + info.storeid + "/" + info.version);

            padclass myTranData = new padclass();
            myTranData.code = "100";
            myTranData.msg = "成功";
            myTranData.catlist = new List<padclass.CatObject>();

            try
            {
                string SQL = "select catno,catname,parentno,level,version "
                  + " from VIEW_PAD_CLASSSTORE"
                  + " where 1=1 ";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    padclass.CatObject mytranhead = new padclass.CatObject();
                    mytranhead.catno = dttranhead.Rows[m]["catno"].ToString();
                    mytranhead.catname = dttranhead.Rows[m]["catname"].ToString();
                    mytranhead.parentno = dttranhead.Rows[m]["parentno"].ToString();
                    mytranhead.level = int.Parse(dttranhead.Rows[m]["level"].ToString());
                    mytranhead.version = dttranhead.Rows[m]["version"].ToString();
                    
                    //主表
                    myTranData.catlist.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("301.服饰-商品分类:" + ex.Message);
                Log.doWriteLog(1, "301.服饰-商品分类:" + ex.Message);
                myTranData.code = "400";
                myTranData.msg = "301.服饰-商品分类查询出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "301.服饰-商品分类处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 服饰--商品资料
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public padplu dogetPluList(padversion info)
        {
            string sStoreId = info.storeid;
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "302.服饰商品资料..." + sStoreId);

            //这里应该读取该门店的餐牌编号，现在先默认
            string sMenuNo = "000504";

            padplu myMenuItem = new padplu();

            myMenuItem.code = "100";
            myMenuItem.msg = "成功";
            myMenuItem.menuCatList = new List<padplu.MenuCatObject>();

            try
            {
                //第二层
                string SQL = " select Fseq,StoName,a.FMENUNO,a.MENUNAME "
                     + "  from Ts_ItemMenuDetail b,Ts_ItemMenu a,Ts_ItemSession s"
                     + "  where 1=1"
                     + "  and s.WAREHID = '" + sStoreId + "'"
                     + "  and s.posno > 90"
                     + "  and s.MENUNO = a.FMENUNO"
                     + "  and a.FMENUNO = b.fMenuNo"
                     + "  order by fseq";
                DataTable myMidCat = myADO.query(SQL);

                //菜品小类下商品
                SQL = "  select b.fBarcode,b.fItemNo,b.fItemName,b.fSellPrice,b.fMemberPrice"
                 + " ,b.fSaleUnit,b.fSpec,b.fItemtype,b.FDISCFLAG"
                 + " ,b.fBClassStNo,b.fMClassStNo,b.fClassStNo,b.FITEMDESC"
                 + " ,ISNULL(c.fInvQty,0) fInvQty,a.FMENUNO,a.Fseq"
                 + " from Ts_ItemMenuDetailSzi a "
                 + " inner join Ts_ItemSession s on s.WAREHID = '" + sStoreId + "' and s.posno > 90 and s.MENUNO = a.FMENUNO"
                 + " left join Ts_Plu b on a.fitemno = b.fItemNo"
                 + " left join (select fitemno,sum(fInvQty) fInvQty from Tc_timeinv  where fOrgno='" + info.storeid + "' group by fitemno ) c on c.fitemno = b.fItemNo"
                 + " where 1=1"
                 + " order by Tseq,Fseq";
                DataTable myCatItem = myADO.query(SQL);

                //条码列表
                SQL = "  select a.fItemNo,a.fBarcode,a.fcolorid,a.fcolorname,a.fsizeid,a.fsizename"
                 + "  ,ISNULL(b.fInvQty,0) fInvQty"
                 + " from Ts_barcode a"
                 + " inner join Ts_ItemSession s on s.WAREHID = '" + sStoreId + "' and s.posno > 90"
                 + " inner join Ts_ItemMenuDetailSzi c on s.MENUNO = c.FMENUNO and c.fItemNo=a.fItemNo"
                 + " left join Tc_timeinv b on b.fOrgNo='" + sStoreId + "' and b.fBarCode=a.fBarCode";
                DataTable mySKU = myADO.query(SQL);

                //第一层
                SQL = "select a.MENUNO,c.MENUNAME"
                  + " from Ts_ItemSession a"
                  + " INNER JOIN dbo.Ts_ItemMenu c on a.MENUNO = c.FMENUNO"
                  + " WHERE(a.WAREHID = '" + sStoreId + "')"
                  + "   and a.posno > 90"
                  + " order by a.MENUNO";
                DataTable dtBigCat = myADO.query(SQL);
                if (dtBigCat is null || dtBigCat.Rows.Count == 0)
                {
                    return null;
                }

                for (int i = 0; i < dtBigCat.Rows.Count; i++)
                {
                    padplu.MenuCatObject myMenuCategoryTreeDTOItem = new padplu.MenuCatObject();
                    myMenuCategoryTreeDTOItem.categoryId = dtBigCat.Rows[i]["MENUNO"].ToString();
                    myMenuCategoryTreeDTOItem.categoryName = dtBigCat.Rows[i]["MENUNAME"].ToString();
                    myMenuCategoryTreeDTOItem.uncheckedIcon = null;
                    myMenuCategoryTreeDTOItem.categoryIcon = null;
                    myMenuCategoryTreeDTOItem.categorySort = i;

                    //第二层 菜品中类
                    myMenuCategoryTreeDTOItem.childList = new List<padplu.ChildObject>();

                    int j = 0;
                    sMenuNo = dtBigCat.Rows[i]["MENUNO"].ToString();
                    DataRow[] MidCat = myMidCat.Select("FMENUNO='" + sMenuNo + "'");//根据查询条件，筛选出所有满足条件的列
                    foreach (var dtMidCat in MidCat)
                    {
                        padplu.ChildObject mychildren = new padplu.ChildObject();
                        mychildren.categoryId = dtMidCat["Fseq"].ToString();
                        mychildren.categoryName = dtMidCat["StoName"].ToString(); ;
                        mychildren.parentCategoryId = dtBigCat.Rows[i]["MENUNO"].ToString(); ;
                        mychildren.uncheckedIcon = null;
                        mychildren.categoryIcon = null;
                        mychildren.categorySort = j;

                        j = j + 1;

                        //第三层 菜品小类
                        mychildren.pluList = new List<padplu.pluObject>();
                        int k = 0;
                        string sSeq = dtMidCat["Fseq"].ToString();

                        DataRow[] MenuItem = myCatItem.Select("FMENUNO='" + sMenuNo + "' and Fseq='"+sSeq+"'");//根据查询条件，筛选出所有满足条件的列
                        foreach (var dtMenuItem in MenuItem)
                        {
                            //saleProductVoList
                            padplu.pluObject mysaleProductVoList = new padplu.pluObject();
                            mysaleProductVoList.customerCode = dtMenuItem["fItemNo"].ToString();
                            mysaleProductVoList.erpCode = dtMenuItem["fBarcode"].ToString();
                            mysaleProductVoList.productName = dtMenuItem["fItemName"].ToString();
                            mysaleProductVoList.unitName = dtMenuItem["fSaleUnit"].ToString();
                            mysaleProductVoList.finalPrice = decimal.Parse(dtMenuItem["fSellPrice"].ToString());
                            mysaleProductVoList.memberPrice = decimal.Parse(dtMenuItem["fMemberPrice"].ToString());
                            mysaleProductVoList.materialClassIdLarge = dtMenuItem["fBClassStNo"].ToString();
                            mysaleProductVoList.materialClassIdMid = dtMenuItem["fMClassStNo"].ToString();
                            mysaleProductVoList.materialClassIdSmall = dtMenuItem["fClassStNo"].ToString();
                            mysaleProductVoList.fdiscflag = int.Parse(dtMenuItem["FDISCFLAG"].ToString());
                            string spicture1= "http://192.168.0.231:8090/Uploads/" + dtMenuItem["fItemNo"].ToString() + ".jpg";
                            spicture1 = spicture1.Replace("\\", "");
                            mysaleProductVoList.picture = spicture1;
                            mysaleProductVoList.productSort = k;
                            mysaleProductVoList.stock =int.Parse(dtMenuItem["fInvQty"].ToString());//该商品库存
                            mysaleProductVoList.type = dtMenuItem["fItemtype"].ToString();
                            mysaleProductVoList.status = 1;
                            mysaleProductVoList.itemdesc = dtMenuItem["FITEMDESC"].ToString();
                            k = k + 1; 

                            //条码列表
                            mysaleProductVoList.skuList = new List<padplu.skuObject>();
                            int z = 0;
                            string sItemNo = dtMenuItem["fItemNo"].ToString();
                            DataRow[] SKUItem = mySKU.Select("fItemNo='" + sItemNo + "'");//根据查询条件，筛选出所有满足条件的列
                            foreach (var dtSKU in SKUItem)
                            {
                                padplu.skuObject mysku = new padplu.skuObject();
                                mysku.skuCode = dtSKU["fBarcode"].ToString();
                                mysku.colorid = dtSKU["fcolorid"].ToString();
                                mysku.colorname = dtSKU["fcolorname"].ToString();
                                mysku.sizeid = dtSKU["fsizeid"].ToString();
                                mysku.sizename = dtSKU["fsizename"].ToString();
                                mysku.stock = int.Parse(dtSKU["fInvQty"].ToString());
                                spicture1 = "http://192.168.0.231:8090/Uploads/" + dtSKU["fItemNo"].ToString() + "-" + dtSKU["fcolorname"].ToString() + ".jpg";
                                spicture1 = spicture1.Replace("\\", "");
                                mysku.picture = spicture1;
                                //该商品条码入库
                                mysaleProductVoList.skuList.Add(mysku);

                            }

                            //该商品加入库
                            mychildren.pluList.Add(mysaleProductVoList);
                        }

                        //添加菜品小类
                        myMenuCategoryTreeDTOItem.childList.Add(mychildren);
                    }

                    //添加商品大类
                    myMenuItem.menuCatList.Add(myMenuCategoryTreeDTOItem);
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("302.服饰-商品资料:" + ex.Message);
                Log.doWriteLog(1, "302.服饰-商品资料:" + ex.Message);
                myMenuItem.code = "400";
                myMenuItem.msg = "302.服饰-商品资料查询出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "302.服饰-商品资料处理完毕");

            return myMenuItem;

        }

        /// <summary>
        /// 服饰--营业员资料
        /// </summary>
        public padman dogetSaleManList(padversion info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "303.服饰-营业员资料..." + info.storeid + "/" + info.version);

            padman myTranData = new padman();
            myTranData.code = "100";
            myTranData.msg = "成功";
            myTranData.salelist = new List<padman.ManObject>();

            try
            {
                string SQL = "select saleno,salename,version "
                  + " from VIEW_PAD_SALEMAN"
                  + " where fOrgNo='"+info.storeid + "'";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    padman.ManObject mytranhead = new padman.ManObject();
                    mytranhead.saleno = dttranhead.Rows[m]["saleno"].ToString();
                    mytranhead.salename = dttranhead.Rows[m]["salename"].ToString();
                    mytranhead.version = dttranhead.Rows[m]["version"].ToString();

                    //主表
                    myTranData.salelist.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("301.服饰-营业员资料:" + ex.Message);
                Log.doWriteLog(1, "301.服饰-营业员资料:" + ex.Message);
                myTranData.code = "400";
                myTranData.msg = "303.服饰-营业员资料查询出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "303.服饰-营业员资料处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 服饰--支付资料
        /// </summary>
        public padpayment dogetPayList(padversion info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "304.服饰-支付资料..." + info.storeid + "/" + info.version);

            padpayment myTranData = new padpayment();
            myTranData.code = "100";
            myTranData.msg = "成功";
            myTranData.paylist = new List<padpayment.PayObject>();

            try
            {
                string SQL = "select payno,payname,seqno,changeflag,paytype,version "
                  + " from VIEW_PAD_PAYMENT"
                  + " where 1=1";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    padpayment.PayObject mytranhead = new padpayment.PayObject();
                    mytranhead.payno = dttranhead.Rows[m]["payno"].ToString();
                    mytranhead.payname = dttranhead.Rows[m]["payname"].ToString();
                    mytranhead.seqno = int.Parse(dttranhead.Rows[m]["seqno"].ToString());
                    mytranhead.changeflag = int.Parse(dttranhead.Rows[m]["changeflag"].ToString());
                    mytranhead.paytype = int.Parse(dttranhead.Rows[m]["paytype"].ToString());
                    mytranhead.version = dttranhead.Rows[m]["version"].ToString();

                    //主表
                    myTranData.paylist.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("304.服饰-支付资料:" + ex.Message);
                Log.doWriteLog(1, "304.服饰-支付资料:" + ex.Message);
                myTranData.code = "400";
                myTranData.msg = "304.服饰-支付资料查询出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "304.服饰-支付资料处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 服饰--支付资料
        /// </summary>
        public padinvlist getPluInvList(padsku info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "305.服饰-他店库存..." + info.storeid + "/" + info.skucode);

            padinvlist myTranData = new padinvlist();
            myTranData.code = "100";
            myTranData.msg = "成功";
            myTranData.invlist = new List<padinvlist.InvObject>();

            try
            {
                string SQL = " select  a.fOrgNo,b.fOrgName,a.fInvQty,convert(varchar(20),a.fInvDate,120) fInvDate"
                  +" from Tc_timeinv a,Ts_Organize b"
                  +" where a.fOrgNo = b.fOrgNo"
                  +" and a.fOrgNo<>'"+info.storeid+"'"
                  +" and a.fBarCode='"+info.skucode+"'";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    padinvlist.InvObject mytranhead = new padinvlist.InvObject();
                    mytranhead.storeid = dttranhead.Rows[m]["fOrgNo"].ToString();
                    mytranhead.storename = dttranhead.Rows[m]["fOrgName"].ToString();
                    mytranhead.invqty = int.Parse(dttranhead.Rows[m]["fInvQty"].ToString());
                    mytranhead.invdate = dttranhead.Rows[m]["fInvDate"].ToString();

                    //主表
                    myTranData.invlist.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("305.服饰-他店库存:" + ex.Message);
                Log.doWriteLog(1, "305.服饰-他店库存:" + ex.Message);
                myTranData.code = "400";
                myTranData.msg = "305.服饰-他店库存查询出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "305.服饰-他店库存处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 服饰-订单查询
        /// </summary>
        public padorddata getOrdList(padordqry info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "306.服饰-订单查询..." + info.storeid + "/" + info.placestartdate + "/" + info.placeenddate);

            padorddata myTranData = new padorddata();
            myTranData.code = 100;
            myTranData.msg = "成功";

            myTranData.tranhead = new List<padorddata.Ttranhead>();

            try
            {
                string SQL = "select id,Flowno"
                  + " ,case Sellway when 'A' then '销售' else '退货' end Sellway"
                  + " ,GrosalAMT, DiscAMT, SaleAmt, OverAmt, ChgAmt, beforeDiscAmt, afterDiscAmt"
                  + " , operId, OperDate,ISNULL(c.fEmpName,saleMan) saleMan, isInRoom,vipNo,b.FMEMNAME "
                  + " ,case isInRoom when 1 then '堂食' else '外带' end isInRoom "
                  + " from epos.dbo.pos_tranhead a"
                  + " left join member.dbo.Ts_memberBase b  on b.fCustId=101 and b.fMemberNo=a.vipNo"
                  + " left join Ts_Employee c on c.fEmpNo=a.saleMan"
                  + " where Warehouseid='" + info.storeid + "'"
                  + " and convert(datetime,OperDate) between convert(datetime,'" + info.placestartdate + "')"
                  + " and convert(datetime,'" + info.placeenddate + "')"
                  + " and Sellway in ('A','B')";

                if (!(info.vipno is null)&& (info.vipno.Length > 0))
                {
                    SQL = SQL + " and vipNo='" + info.vipno + "'";
                }

                if (!(info.saleman is null)&&(info.saleman.Length > 0))
                {
                    SQL = SQL + " and saleMan='" + info.saleman + "'";
                }

                SQL = SQL + " order by flowno";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    padorddata.Ttranhead mytranhead = new padorddata.Ttranhead();
                    mytranhead.orderid = int.Parse(dttranhead.Rows[m]["id"].ToString());
                    mytranhead.orderno = dttranhead.Rows[m]["Flowno"].ToString();
                    mytranhead.sellway = dttranhead.Rows[m]["Sellway"].ToString();
                    mytranhead.orderdate = dttranhead.Rows[m]["OperDate"].ToString();
                    mytranhead.vipno = dttranhead.Rows[m]["vipNo"].ToString();
                    mytranhead.vipname = dttranhead.Rows[m]["FMEMNAME"].ToString();
                    mytranhead.ordertype = dttranhead.Rows[m]["isInRoom"].ToString();
                    mytranhead.orderAmt = decimal.Parse(dttranhead.Rows[m]["GrosalAMT"].ToString());
                    mytranhead.discAmt = dttranhead.Rows[m]["DiscAMT"].ToString();
                    mytranhead.saleAmt = dttranhead.Rows[m]["SaleAmt"].ToString();
                    mytranhead.saleman = dttranhead.Rows[m]["saleMan"].ToString();

                    mytranhead.trandtl = new List<padorddata.Ttrandtl>();

                    string SQL2 = "select itemseq,pluno,barcode,pluname,salePrice,DiscAmt,convert(int,saleQty) saleQty,saleAmt"
                        + " ,b.fcolorname,b.fsizename"
                        + " from epos.dbo.pos_tranflow a"
                        + " left join Ts_Barcode b on b.fBarCode=a.barcode"
                        + " where Warehouseid='" + info.storeid + "'"
                        + " and flowno ='" + dttranhead.Rows[m]["Flowno"].ToString() + "'"
                        + " order by id";
                    DataTable dttrandtl = myADO.query(SQL2);
                    for (int i = 0; i < dttrandtl.Rows.Count; i++)
                    {
                        padorddata.Ttrandtl mytrandtl = new padorddata.Ttrandtl();
                        mytrandtl.line = int.Parse(dttrandtl.Rows[i]["itemseq"].ToString());
                        mytrandtl.pluno = dttrandtl.Rows[i]["pluno"].ToString();
                        mytrandtl.erpcode = dttrandtl.Rows[i]["barcode"].ToString();
                        mytrandtl.pluname = dttrandtl.Rows[i]["pluname"].ToString();
                        mytrandtl.pluprice = decimal.Parse(dttrandtl.Rows[i]["salePrice"].ToString());
                        mytrandtl.qty = int.Parse(dttrandtl.Rows[i]["saleQty"].ToString());
                        mytrandtl.discount = decimal.Parse(dttrandtl.Rows[i]["DiscAmt"].ToString());
                        mytrandtl.amt = decimal.Parse(dttrandtl.Rows[i]["saleAmt"].ToString());
                        mytrandtl.colorname = dttrandtl.Rows[i]["fcolorname"].ToString();
                        mytrandtl.sizename = dttrandtl.Rows[i]["fsizename"].ToString();

                        mytranhead.trandtl.Add(mytrandtl);
                    }
                    //交易主表
                    myTranData.tranhead.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("306.服饰-订单查询出错:" + ex.Message);
                Log.doWriteLog(1, "306.服饰-订单查询出错:" + ex.Message);
                myTranData.code = 400;
                myTranData.msg = "306.服饰-订单查询出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "306.服饰-订单查询处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 服饰--外卖订单
        /// </summary>
        public padshopord getShopOrdList(WMOrdQry info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "307.服饰--外卖订单..." + info.storeId + "/" + info.orderId.ToString());

            padshopord myTranData = new padshopord();
            myTranData.code = 100;
            myTranData.msg = "成功";
            myTranData.tranhead = new List<padshopord.WMHeadObject>();

            try
            {
                string SQL = "select top 5 id,channelSheetno,channelKeyword,billtype"
                 + " , returnOrderSn, totalSaleValue, totalDiscValue"
                 + " ,startDeliveryTime, convert(varchar(20),endDeliveryTime,120) endDeliveryTime, status, orgCode"
                 + ", orderTime, receiverName, receiverGender, receiverMobile"
                 + ", receiverAddress, note, receiverType"
                 + " from epos.dbo.takeaway_order_head"
                 + "  where id>" + info.orderId.ToString()
                 + "  and orgCode='" + info.storeId + "'"
                 + " order by id";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    padshopord.WMHeadObject mytranhead = new padshopord.WMHeadObject();
                    mytranhead.orderid = int.Parse(dttranhead.Rows[m]["id"].ToString());
                    mytranhead.orderno = dttranhead.Rows[m]["channelSheetno"].ToString();
                    mytranhead.orderdate = dttranhead.Rows[m]["orderTime"].ToString();
                    mytranhead.orderstye = dttranhead.Rows[m]["channelKeyword"].ToString();
                    mytranhead.vipno = dttranhead.Rows[m]["receiverGender"].ToString();
                    mytranhead.vipname = dttranhead.Rows[m]["receiverName"].ToString();
                    mytranhead.telno = dttranhead.Rows[m]["receiverMobile"].ToString();
                    mytranhead.orderamt = decimal.Parse(dttranhead.Rows[m]["totalSaleValue"].ToString());
                    mytranhead.ordertype = dttranhead.Rows[m]["receiverType"].ToString();
                    mytranhead.ordertime = dttranhead.Rows[m]["endDeliveryTime"].ToString();
                    mytranhead.address = dttranhead.Rows[m]["receiverAddress"].ToString();
                    mytranhead.memo = dttranhead.Rows[m]["note"].ToString();
                    mytranhead.orderstate = int.Parse(dttranhead.Rows[m]["status"].ToString());
                    mytranhead.trandtl = new List<padshopord.WMDtlObject>();

                    string SQL2 = "select channelSheetno,seq,itemCode,barcode,name,qriginalPrice,salePrice"
                      + " , discValue, bcatno,scatno, qty, money"
                      + " from epos.dbo.takeaway_order_detail"
                      + " where channelSheetno='" + dttranhead.Rows[m]["channelSheetno"].ToString() + "'"
                      + " order by id";
                    DataTable dttrandtl = myADO.query(SQL2);
                    for (int i = 0; i < dttrandtl.Rows.Count; i++)
                    {
                        padshopord.WMDtlObject mytrandtl = new padshopord.WMDtlObject();
                        mytrandtl.line = int.Parse(dttrandtl.Rows[i]["seq"].ToString());
                        mytrandtl.pluno = dttrandtl.Rows[i]["barcode"].ToString();
                        mytrandtl.pluname = dttrandtl.Rows[i]["name"].ToString();
                        mytrandtl.pluprice = decimal.Parse(dttrandtl.Rows[i]["salePrice"].ToString());
                        mytrandtl.qty = int.Parse(dttrandtl.Rows[i]["qty"].ToString());
                        mytrandtl.amt = decimal.Parse(dttrandtl.Rows[i]["money"].ToString());
                        mytrandtl.colorname = dttrandtl.Rows[i]["bcatno"].ToString();
                        mytrandtl.sizename = dttrandtl.Rows[i]["scatno"].ToString();

                        mytranhead.trandtl.Add(mytrandtl);
                    }

                    //交易主表
                    myTranData.tranhead.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("307.服饰--外卖订单出错:" + ex.Message);
                Log.doWriteLog(1, "307.服饰--外卖订单出错:" + ex.Message);
                myTranData.code = 400;
                myTranData.msg = "307.服饰--外卖订单处理出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "407.服饰--外卖订单处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 服饰--退货上传
        /// </summary>
        public BACKDATA setreturn(padreturn info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "308.服饰--退货上传..." + info.storeid + "/" + info.tranno);

            string sOrdId = string.Empty;

            BACKDATA myOrdDataInfo = new BACKDATA();
            myOrdDataInfo.code = "100";
            try
            {
                string sShiftFlowNo = info.posno + DateTime.Now.ToString("yyyyMMdd") + "0001";

                //是否已经退货
                string SQL = "select 1 from epos.dbo.pos_backhead where  WarehouseID='" + info.storeid + "'"
                   + " and PosNo='" + info.posno + "'"
                   + " and flowno='" + info.tranno + "'";
                DataTable dttran = myADO.query(SQL);
                if (!(dttran is null) && (dttran.Rows.Count > 0))
                {
                    myOrdDataInfo.code = "202";
                    myOrdDataInfo.msg = "202.已退货";
                    return myOrdDataInfo;
                }

                //是否是退货交易
                SQL = "select Sellway from epos.dbo.pos_tranhead where  WarehouseID='" + info.storeid + "'"
                   + " and PosNo='" + info.posno + "'"
                   + " and flowno='" + info.tranno + "'";
                dttran = myADO.query(SQL);
                if (!(dttran is null) && (dttran.Rows.Count > 0))
                {
                    if (dttran.Rows[0][0].ToString().Equals("B"))
                    {
                        myOrdDataInfo.code = "203";
                        myOrdDataInfo.msg = "203.退货交易不能退货";
                        return myOrdDataInfo;
                    }
                    
                }

                SQL = "exec PROC_POS_DOCHECKSHIFT '" + info.storeid + "'"
                   + ",'" + info.posno + "'"
                   + ",'" + info.cashierid + "'";
                dttran = myADO.query(SQL);
                if (dttran.Rows[0][0].ToString().Equals("100"))
                {
                    myOrdDataInfo.code = "201";
                    myOrdDataInfo.msg = "201.请先开班";
                    return myOrdDataInfo;
                }
                sShiftFlowNo = dttran.Rows[0][5].ToString(); //当前班别号

                

                myADO.SQLList.Clear();

                string sAccDate = DateTime.Now.ToString("yyyy-MM-dd");

                //解析订单
                string productInfoJson = info.productInfoJson;
                List<padreturn.SKUData> myOrdItem = JsonConvert.DeserializeObject<List<padreturn.SKUData>>(productInfoJson);//反序列化
                for (int i = 0; i < myOrdItem.Count; i++)
                {
                    //Console.WriteLine(myOrdItem[i].pluName);
                    SQL = "insert into epos.dbo.pos_backflow(WarehouseID,PosNo,flowno,itemseq)"
                     + " values('" + info.storeid + "'"
                     + ",'" + info.posno + "'"
                     + ",'" + info.tranno + "'"
                     + "," + myOrdItem[i].line.ToString()
                     + ")";
                    myADO.SQLList.Add(SQL);
                }

                SQL = "insert into epos.dbo.pos_backhead(Warehouseid,PosNo,OperDate,Flowno,operId,GrosalAMT,DiscAMT,SaleAmt)"
                 + " values('"+ info.storeid + "'"
                 + ",'" + info.posno + "'"
                 + ",'" + info.systemdate + "'"
                 + ",'"+info.tranno+"'"
                 + ",'"+info.cashierid+"'"
                 + " ," + info.totalprice.ToString() 
                 + ", " + info.totaldiscount.ToString()
                 + "," + info.payprice.ToString()
                 + ")";
                myADO.SQLList.Add(SQL);

                bool IsOk = false;
                string sError = string.Empty;
                myADO.doSave(out IsOk, out sError);

                //返回

                if (!IsOk)
                {
                    myOrdDataInfo.code = "101";
                }
                else
                {
                    SQL = "exec PROC_POS_DORETURN '" + info.storeid + "'"
                     + ",'" + info.posno + "'"
                     + ",'" + info.tranno + "'";
                    dttran = myADO.query(SQL);
                    myOrdDataInfo.code = dttran.Rows[0][0].ToString();
                    myOrdDataInfo.msg = dttran.Rows[0][1].ToString();
                }
                myOrdDataInfo.msg = sError;
            }
            catch (Exception ex)
            {
                Console.WriteLine("308.服饰--退货上传出错:" + ex.Message);
                Log.doWriteLog(1, "308.服饰--退货上传出错:" + ex.Message);
                myOrdDataInfo.code = "400";
                myOrdDataInfo.msg = "308.服饰--退货上传出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "308.服饰--退货上传处理完毕," + sOrdId);

            return myOrdDataInfo;
        }

        /// <summary>
        /// 服饰--库存查询
        /// </summary>
        public padinvdata getinvlist(padinvqry info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "309.服饰--库存查询..." + info.storeid );

            padinvdata myTranData = new padinvdata();
            myTranData.code = 100;
            myTranData.msg = "成功";
            myTranData.invlist = new List<padinvdata.InvObject>();

            try
            {
                string SQL = "select c.fItemNo,c.fItemName,c.fSellPrice,b.fBarcode,b.fcolorname,b.fsizename"
                  + "  , a.fInvQty,convert(varchar(20), a.fInvDate, 120) fInvDate"
                  + "  from Tc_timeinv a, Ts_Barcode b,Ts_PLU c"
                  + "  where a.fOrgNo = '"+info.storeid+"'"
                  + "  and a.fBarCode = b.fBarcode"
                  + "  and a.fItemNo = c.fItemNo";
                if (!(info.bcatno is null) && (info.bcatno.Length > 0))
                {
                    SQL = SQL + " and c.fBClassStNo='" + info.bcatno + "'";
                }

                if (!(info.mcatno is null) && (info.mcatno.Length > 0))
                {
                    SQL = SQL + " and c.fMClassStNo='" + info.mcatno + "'";
                }

                if (!(info.scatno is null) && (info.scatno.Length > 0))
                {
                    SQL = SQL + " and c.fClassStNo='" + info.scatno + "'";
                }

                if (!(info.pluno is null) && (info.pluno.Length > 0))
                {
                    SQL = SQL + " and c.fitemno like '" + info.pluno + "%'";
                }

                SQL = SQL + " order by c.fitemno";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    padinvdata.InvObject mytranhead = new padinvdata.InvObject();
                    mytranhead.itemno = dttranhead.Rows[m]["fItemNo"].ToString();
                    mytranhead.pluname = dttranhead.Rows[m]["fItemName"].ToString();
                    mytranhead.saleamt = decimal.Parse(dttranhead.Rows[m]["fSellPrice"].ToString());
                    mytranhead.erpcode = dttranhead.Rows[m]["fBarcode"].ToString();
                    mytranhead.invqty = int.Parse(dttranhead.Rows[m]["fInvQty"].ToString());
                    mytranhead.colorname = dttranhead.Rows[m]["fcolorname"].ToString();
                    mytranhead.sizename = dttranhead.Rows[m]["fsizename"].ToString();
                    mytranhead.invdate = dttranhead.Rows[m]["fInvDate"].ToString();

                    //交易主表
                    myTranData.invlist.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("309.服饰--库存查询出错:" + ex.Message);
                Log.doWriteLog(1, "309.服饰--库存查询出错:" + ex.Message);
                myTranData.code = 400;
                myTranData.msg = "309.服饰--库存查询处理出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "309.服饰--库存查询处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 服饰-业绩报表
        /// </summary>
        public pdatimesale gettimesale(pdareport info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "310.服饰-业绩报表..." + info.storeid + "/" + info.begdate + "/" + info.enddate);

            pdatimesale myTranData = new pdatimesale();
            myTranData.code = 100;
            myTranData.msg = "成功";

            myTranData.timelist = new List<pdatimesale.timeObject>();

            try
            {
                string SQL = "exec PROC_POS_DOGETTIMESALE '"+info.storeid+"'" 
                  +",'"+info.begdate+"'"
                  +",'"+info.enddate+"'";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    pdatimesale.timeObject mytranhead = new pdatimesale.timeObject();
                    mytranhead.saletime = dttranhead.Rows[m]["ftime"].ToString();
                    mytranhead.saleamt =decimal.Parse(dttranhead.Rows[m]["saleAmt"].ToString());
                    mytranhead.salenum =int.Parse(dttranhead.Rows[m]["custNumber"].ToString());

                    myTranData.f01 = decimal.Parse(dttranhead.Rows[m]["f01"].ToString());
                    myTranData.f02 = decimal.Parse(dttranhead.Rows[m]["f02"].ToString());
                    myTranData.f03 = decimal.Parse(dttranhead.Rows[m]["f03"].ToString());
                    
                    //交易主表
                    myTranData.timelist.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("310.服饰-业绩报表出错:" + ex.Message);
                Log.doWriteLog(1, "310.服饰-业绩报表出错:" + ex.Message);
                myTranData.code = 400;
                myTranData.msg = "310.服饰-业绩报表出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "310.服饰-业绩报表处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 服饰-营业员提成
        /// </summary>
        public padmansale getmanamt(pdareport info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "311.服饰-营业员提成..." + info.storeid + "/" + info.begdate + "/" + info.enddate);

            padmansale myTranData = new padmansale();
            myTranData.code = 100;
            myTranData.msg = "成功";

            myTranData.timelist = new List<padmansale.timeObject>();

            try
            {
                string SQL = "exec PROC_POS_DOGETMANSALE '" + info.storeid + "'"
                  + ",'" + info.begdate + "'"
                  + ",'" + info.enddate + "'";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    padmansale.timeObject mytranhead = new padmansale.timeObject();
                    mytranhead.saleno = dttranhead.Rows[m]["saleMan"].ToString();
                    mytranhead.saleman = dttranhead.Rows[m]["fEmpName"].ToString();
                    mytranhead.saleamt = decimal.Parse(dttranhead.Rows[m]["saleAmt"].ToString());
                    mytranhead.salenum = int.Parse(dttranhead.Rows[m]["custNumber"].ToString());
                    mytranhead.rateamt = decimal.Parse(dttranhead.Rows[m]["rateamt"].ToString());

                    //交易主表
                    myTranData.timelist.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("311.服饰-营业员提成出错:" + ex.Message);
                Log.doWriteLog(1, "311.服饰-营业员提成出错:" + ex.Message);
                myTranData.code = 400;
                myTranData.msg = "311.服饰-营业员提成出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "311.服饰-营业员提成处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 服饰-销售排行榜
        /// </summary>
        public padplusale getplutime(pdareport info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "312.服饰-销售排行榜..." + info.storeid + "/" + info.begdate + "/" + info.enddate);

            padplusale myTranData = new padplusale();
            myTranData.code = 100;
            myTranData.msg = "成功";

            myTranData.bcatlist = new List<padplusale.CatObject>();
            myTranData.mcatlist = new List<padplusale.CatObject>();
            myTranData.plulist = new List<padplusale.PluObject>();

            try
            {
                string SQL = "exec PROC_POS_DOGETPLUTIMESALE 1,'" + info.storeid + "'"
                  + ",'" + info.begdate + "'"
                  + ",'" + info.enddate + "'";
                DataTable dttran1 = myADO.query(SQL);
                for (int m = 0; m < dttran1.Rows.Count; m++)
                {
                    padplusale.CatObject mytranhead = new padplusale.CatObject();
                    mytranhead.catname = dttran1.Rows[m]["catname"].ToString();
                    mytranhead.saleamt = decimal.Parse(dttran1.Rows[m]["saleAmt"].ToString());

                    //交易主表
                    myTranData.bcatlist.Add(mytranhead);
                }

                SQL = "exec PROC_POS_DOGETPLUTIMESALE 2,'" + info.storeid + "'"
                  + ",'" + info.begdate + "'"
                  + ",'" + info.enddate + "'";
                DataTable dttran2 = myADO.query(SQL);
                for (int i = 0; i < dttran2.Rows.Count; i++)
                {
                    padplusale.CatObject mytranhead = new padplusale.CatObject();
                    mytranhead.catname = dttran2.Rows[i]["catname"].ToString();
                    mytranhead.saleamt = decimal.Parse(dttran2.Rows[i]["saleAmt"].ToString());

                    //交易主表
                    myTranData.mcatlist.Add(mytranhead);
                }

                SQL = "exec PROC_POS_DOGETPLUTIMESALE 3,'" + info.storeid + "'"
                  + ",'" + info.begdate + "'"
                  + ",'" + info.enddate + "'";
                DataTable dttran3 = myADO.query(SQL);
                for (int j = 0; j < dttran2.Rows.Count; j++)
                {
                    padplusale.PluObject mytranhead = new padplusale.PluObject();
                    mytranhead.f01 = j + 1;
                    mytranhead.f02 = dttran3.Rows[j]["fItemNo"].ToString();
                    mytranhead.f03 = dttran3.Rows[j]["fItemName"].ToString();
                    mytranhead.f04 = int.Parse(dttran3.Rows[j]["saleQty"].ToString());
                    mytranhead.f05 = decimal.Parse(dttran3.Rows[j]["saleAmt"].ToString());

                    //交易主表
                    myTranData.plulist.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("312.服饰-销售排行榜出错:" + ex.Message);
                Log.doWriteLog(1, "312.服饰-销售排行榜出错:" + ex.Message);
                myTranData.code = 400;
                myTranData.msg = "312.服饰-销售排行榜出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "312.服饰-销售排行榜处理完毕");

            return myTranData;
        }

        /// <summary>
        /// 服饰-查询商品库存
        /// </summary>
        public ItemInv doqueryiteminv(qryiteminv info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "313.服饰-查询商品库存..." + info.storeid + "/" + info.idata);

            ItemInv myendList = new ItemInv();
            myendList.code = "100";
            myendList.msg = "成功";
            myendList.content = new List<ItemInv.invList>();
            try
            {
                string SQL = string.Empty; 

                if (info.itype == 1)
                {
                    SQL = "  select a.fitemno,ISNULL(b.fInvQty,0) fInvQty"
                     + " from ts_plu a"
                     + " inner join Ts_ItemMenuDetailSzi s on s.FMENUNO='" + info.idata+"' and s.fitemno=a.fitemno"
                     + " left join (select fitemno,sum(fInvQty) fInvQty from Tc_timeinv where forgno = '"+info.storeid+"' group by fitemno) b on b.fitemno = a.fitemno"
                     + " where 1 = 1"
                     + " order by a.fitemno ";
                }
                else
                {
                    SQL = "  select a.fitemno,ISNULL(b.fInvQty,0) fInvQty"
                     + " from ts_plu a"
                     + " inner join (select fitemno,sum(fInvQty) fInvQty from Tc_timeinv where forgno = '" + info.storeid + "' and fBarCode='"+info.idata+"' group by fitemno) b on b.fitemno = a.fitemno"
                     + " where 1 = 1"
                     + " order by a.fitemno ";
                }
                DataTable dttranhead = myADO.query(SQL);
                for (int j = 0; j < dttranhead.Rows.Count; j++)
                {
                    ItemInv.invList mytranhead = new ItemInv.invList();
                    mytranhead.fitemno = dttranhead.Rows[j]["fitemno"].ToString();
                    mytranhead.fInvQty = int.Parse(dttranhead.Rows[j]["fInvQty"].ToString());

                    //交易主表
                    myendList.content.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("313.服饰-查询商品库存:" + ex.Message);
                Log.doWriteLog(1, "313.服饰-查询商品库存:" + ex.Message);
                myendList.code = "400";
                myendList.msg = "313.服饰-查询商品库存内部处理错误";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "313.服饰-查询商品库存");

            return myendList;
        }

        /// <summary>
        /// 901:会员登陆--配合JAVA中台
        /// </summary>
        public JAVAMemberInfo doJAVAMemberLogin(JAVAMemberQry info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "901.会员登陆..." + info.memberNo);

            JAVAMemberInfo myMemberInfo = new JAVAMemberInfo();
            myMemberInfo.code = "200";
            myMemberInfo.msg = "成功";

            JAVAMemberInfo.Content myContent = new JAVAMemberInfo.Content();
            myMemberInfo.content = myContent;

            try
            {
                //1.检查当前单号状态
                string SQL = "SELECT FMEMBERNO,ISNULL(FMEMNAME,FWXNO) FMEMNAME,FLEVELNAME,FMEMSTATUS"
                 + ", CASE FLEVELSTYLE WHEN 1 THEN '会员折扣' WHEN 2 THEN '会员特价' END FTYPENAME"
                 + ", FLEVELSTYLE,FDISCOUNT, FENABLEPOINT"
                 + ", convert(varchar(10),FBIRTHDAY,120) FBIRTHDAY"
                 + ", convert(varchar(10),FEXPDATE,120) FEXPDATE"
                 + "  FROM Member.dbo.TS_MEMBERBASE A,Member.dbo.TS_MEMBERLEVEL B"
                 + "  WHERE A.FCUSTID = 101"
                 + "    AND A.FCUSTID = B.FCUSTID"
                 + "    AND A.FLEVELNO = B.FLEVELNO"
                 + "    AND((FMEMBERNO = '" + info.memberNo + "' OR FMOBILE = '" + info.memberNo + "'))";
                DataTable dttran = myADO.query(SQL);
                if (dttran is null || dttran.Rows.Count == 0)
                {
                    myMemberInfo.code = "201";
                    myMemberInfo.msg = "会员编号不正确";
                }
                else
                {
                    if (!dttran.Rows[0]["FMEMSTATUS"].ToString().Equals("1"))
                    {
                        myMemberInfo.code = "202";
                        myMemberInfo.msg = "该会员不允许登陆";
                    }
                    else
                    {
                        myContent.memberno = dttran.Rows[0]["FMEMBERNO"].ToString();
                        myContent.membername = dttran.Rows[0]["FMEMNAME"].ToString();
                        myContent.discname = dttran.Rows[0]["FLEVELNAME"].ToString();
                        myContent.discmode = int.Parse(dttran.Rows[0]["FLEVELSTYLE"].ToString());
                        myContent.membergrade = dttran.Rows[0]["FTYPENAME"].ToString();
                        myContent.discamount = Convert.ToDecimal(dttran.Rows[0]["FDISCOUNT"].ToString());
                        myContent.memberintegral = Convert.ToInt32(dttran.Rows[0]["FENABLEPOINT"].ToString());
                        myContent.cardamount = 0;
                        myContent.memberbirthday = dttran.Rows[0]["FBIRTHDAY"].ToString();
                        myContent.cardterm = dttran.Rows[0]["FEXPDATE"].ToString();
                        myContent.purchaseqty = 0;
                        myContent.purchaseamt = 0;
                    }

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("901.会员登陆出错:" + ex.Message);
                Log.doWriteLog(1, "901.会员登陆出错:" + ex.Message);
                myMemberInfo.code = "400";
                myMemberInfo.msg = "901.会员登陆出错";
            }

            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "901.会员登陆处理完毕");

            return myMemberInfo;
        }

        /// <summary>
        /// 902:获取会员礼券号码--配合JAVA中台
        /// </summary>
        public JAVATICKETINFO doJAVAGetTicketInfo(JAVAMemberQry info)
        {
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "902.会员礼券列表..." + info.warehouseid + "/" + info.memberNo);

            JAVATICKETINFO myTICKETLIST = new JAVATICKETINFO();
            myTICKETLIST.code = 200;
            myTICKETLIST.msg = "成功";

            myTICKETLIST.ticketlist = new List<JAVATICKETINFO.MemberTicket>();

            try
            {
                string SQL = "SELECT A.FTICKETNO,A.FPUBLISHNOTE FTICKETCATNAME,FBATCHNO"
                  + " ,CONVERT(VARCHAR(10),FBEGDATE,120)FBEGDATE"
                  + " ,CONVERT(VARCHAR(10),FENDDATE,120)FENDDATE"
                  + " ,CASE FCALFIELD WHEN 1 THEN '消费' ELSE '购买' END + CONVERT(VARCHAR(10), CONVERT(INT, FCALMONEY)) + CASE FCALFIELD WHEN 1 THEN '元' ELSE '个' END + CASE FCALTYPE WHEN 1 THEN '折让' ELSE '折扣' END + CONVERT(VARCHAR(10), FFULLMONEY) FTITLE"
                  + " , FNUM,FTICKETTYPE,FCALFIELD,FCALMONEY,FCALTYPE,FFULLMONEY,FUSELIMIT"
                  + " FROM Member.dbo.TS_TICKETCAT B"
                  + ",(SELECT a.FCUSTID,a.FTICKETNO,a.FTICKETCATNO,a.FBATCHNO,c.FPUBLISHNOTE,a.FBEGDATE,a.FENDDATE, 1 FNUM"
                  + "   FROM Member.dbo.TS_TICKET a,Member.dbo.TC_TICKETPUBLISH c"
                  + "  WHERE a.FCUSTID = 101"
                  + "    AND FMEMBERNO = '" + info.memberNo + "'"
                  + "    AND CONVERT(VARCHAR(10), GETDATE(), 120) BETWEEN a.FBEGDATE AND a.FENDDATE"
                  + "    AND a.FSTATUS = 1"
                  + "    AND a.FCUSTID=c.FCUSTID"
                  + "    AND a.FBATCHNO = c.FBATCHNO) A"
                  + "    WHERE A.FCUSTID = B.FCUSTID"
                  + "  AND A.FTICKETCATNO = B.FTICKETCATNO";
                DataTable dttranhead = myADO.query(SQL);
                for (int m = 0; m < dttranhead.Rows.Count; m++)
                {
                    JAVATICKETINFO.MemberTicket mytranhead = new JAVATICKETINFO.MemberTicket();
                    mytranhead.ticketno = dttranhead.Rows[m]["FTICKETNO"].ToString();
                    mytranhead.ticketname = dttranhead.Rows[m]["FTICKETCATNAME"].ToString();
                    mytranhead.begdate = dttranhead.Rows[m]["FBEGDATE"].ToString();
                    mytranhead.enddate = dttranhead.Rows[m]["FENDDATE"].ToString();
                    mytranhead.tickettitle = dttranhead.Rows[m]["FTITLE"].ToString();
                    mytranhead.surplusnum = int.Parse(dttranhead.Rows[m]["FNUM"].ToString());
                    mytranhead.tickettype = int.Parse(dttranhead.Rows[m]["FTICKETTYPE"].ToString());
                    mytranhead.calfield = int.Parse(dttranhead.Rows[m]["FCALFIELD"].ToString());
                    mytranhead.calmoney = decimal.Parse(dttranhead.Rows[m]["FCALMONEY"].ToString());
                    mytranhead.ticketdiscmode = int.Parse(dttranhead.Rows[m]["FCALTYPE"].ToString());
                    mytranhead.ticketdiscamt = decimal.Parse(dttranhead.Rows[m]["FFULLMONEY"].ToString());
                    mytranhead.usenum = int.Parse(dttranhead.Rows[m]["FUSELIMIT"].ToString());
                    mytranhead.facevalue = 0;

                    //兑换商品
                    mytranhead.foodList = new List<JAVATICKETINFO.TicketItem>();

                    string SQL2 = "  SELECT FCATSCORE,B.FITEMNO"
                      + " FROM Member.dbo.TC_TICKETPUBLISH A"
                      + " LEFT JOIN Member.dbo.TC_TICKETPUBLISH_ITEM B ON A.FCUSTID = B.FCUSTID AND A.FBATCHNO = B.FBATCHNO"
                      + " WHERE A.FCUSTID = 101"
                      + " AND A.FBATCHNO = '" + dttranhead.Rows[m]["FBATCHNO"].ToString() + "'";
                    DataTable dttrandtl = myADO.query(SQL2);
                    for (int i = 0; i < dttrandtl.Rows.Count; i++)
                    {
                        JAVATICKETINFO.TicketItem mytrandtl = new JAVATICKETINFO.TicketItem();
                        mytrandtl.catscore = int.Parse(dttrandtl.Rows[i]["FCATSCORE"].ToString());
                        mytrandtl.foodno = dttrandtl.Rows[i]["FITEMNO"].ToString();

                        //礼券使用商品列表
                        mytranhead.foodList.Add(mytrandtl);
                    }

                    //交易主表
                    myTICKETLIST.ticketlist.Add(mytranhead);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("902.会员礼券列表出错:" + ex.Message);
                Log.doWriteLog(1, "902.会员礼券列表出错:" + ex.Message);
                myTICKETLIST.code = 400;
                myTICKETLIST.msg = "902.会员礼券列表出错";
            }
            Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "902.会员礼券列表");

            return myTICKETLIST;
        }

        /* 配合c#-pos的2个接口
           
        3.1主档更新检测 
        http://39.165.251.192:6069/v20/api/cashier/masterVersionCheck

        3.5交易上传
        http://39.165.251.192:6069/coco/postablet/order/createOrder
        
         */

        /// <summary>
        /// 3.1主档更新检测 
        /// </summary>
        public s_plucheck masterVersionCheck(c_plucheck info)
        {
            this.EnableCrossDmain();

            try
            {
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "3.1主档更新检测:"+ info.shpno);

                s_plucheck mydeskOrder = new s_plucheck();

                mydeskOrder.result = "0";
                mydeskOrder.status = "success";
                mydeskOrder.msg = "需要更新";
                mydeskOrder.down_flag = "1";

                ulrData mydeskData = new ulrData();
                mydeskData.sqlite = "http://192.168.0.138:8090/Uploads/"+info.shpno+"/master.db";
                mydeskData.goods = "http://192.168.0.138:8090/Uploads/goods.zip";

                mydeskOrder.down_url = mydeskData;
                mydeskOrder.shp_ver = "2212270002";
                mydeskOrder.timestamp = "";
                mydeskOrder.sign_type = "";
                mydeskOrder.sign = "";
                
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "完成:" + info.shpno);

                return mydeskOrder;
            }
            catch (Exception ex)
            {
                Console.WriteLine("102.POS获取扫描点单:" + ex.Message);
                Log.doWriteLog(1, "102.POS获取扫描点单:" + ex.Message);
                s_plucheck mydeskOrder = new s_plucheck();

                mydeskOrder.result = "1";
                mydeskOrder.status = "fail";
                mydeskOrder.msg = ex.Message;
                mydeskOrder.down_flag = "0";
                return mydeskOrder;
            }

        }

        /// <summary>
        /// 3.5交易上传
        /// </summary>
        public s_postran createOrder(c_postran info)
        {
            this.EnableCrossDmain();

            try
            {
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "3.5 tranNumber:" + info.tranNumber);

                s_postran myOrdDataInfo = new s_postran();
                myOrdDataInfo.result = "0";
                myOrdDataInfo.status = "success";
                myOrdDataInfo.msg = "tranNumber success";

                //订单号
                myADO.SQLList.Clear();

                string sAccDate = DateTime.Now.ToString("yyyy-MM-dd");
                string SQL = string.Empty;
                string soperDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                Decimal tDiscAMT = 0;
                Decimal tSaleAmt = 0;
                Decimal tbeforeDiscAmt = 0;
                Decimal tafterDiscAmt = 0;

                //解析订单明细
                string productInfoJson = info.productInfoJson;
                if ((productInfoJson == null) || (productInfoJson.Length == 0))
                {

                }
                else
                {
                    List<c_postran.trandtl> myOrdItem = JsonConvert.DeserializeObject<List<c_postran.trandtl>>(info.productInfoJson);//反序列化
                    for (int i = 0; i < myOrdItem.Count; i++)
                    {
                        //Console.WriteLine(myOrdItem[i].pluName);
                        Decimal iUnitPrice = Decimal.Parse(myOrdItem[i].pluPrice.ToString());
                        int iSaleQty = int.Parse(myOrdItem[i].qty.ToString());
                        Decimal iDiscAmt = Decimal.Parse(myOrdItem[i].disamt.ToString());
                        Decimal ibeforeDiscAmt = Decimal.Parse(myOrdItem[i].disamt.ToString());
                        Decimal iafterDiscAmt = 0;
                        Decimal isaleAmt = iSaleQty * iUnitPrice - iDiscAmt;

                        tDiscAMT = tDiscAMT + iDiscAmt;
                        tSaleAmt = tSaleAmt + isaleAmt;
                        tbeforeDiscAmt = tbeforeDiscAmt + ibeforeDiscAmt;
                        tafterDiscAmt = tafterDiscAmt + iafterDiscAmt;

                        SQL = "insert into epos.dbo.pos_tranflow(itemseq,flowno,WarehouseID,pluno"
                            + ",unitPrice,salePrice,avPrice,saleQty,DiscAmt,beforeDiscAmt,afterDiscAmt"
                            + ",isDirectDisc,DiscStr,saleAmt,SuitNo,FoodType,orgSuitDetail,sellWay"
                            + ",operId,saleMan,operDate,Uploadflag,ShiftFlowNo,AccDate,OpenDeskDate"
                            + ",DeskProperty,uniqueID,bcatno,scatno,ChangePriceFlag,ChangePriceAmt"
                            + ",mpluno,saleManName,TasteMemo,DiscFlag,MemberPoint,CardNo,FeedList"
                            + ",TCAmt,PosNo,BaseAmt,MMDiscAmt,tasteTotalAmt,ServiceAmt,sign"
                            + ",TaxID,TaxAmt,custId,pluname,barcode,ulFlag,fClassStNo,tariffNo"
                            + ",tariffName,custNumber,fConID,fCreateDate,actId,tasteHand)"
                            + " values(" + (i + 1).ToString() + ",'" + info.tranNumber + "'"
                            + ",'" + info.storeId + "','" + myOrdItem[i].customerCode.ToString() + "'"
                            + "," + iUnitPrice.ToString()
                            + "," + iUnitPrice.ToString()
                            + ",0," + iSaleQty.ToString()
                            + "," + iDiscAmt.ToString()
                            + "," + ibeforeDiscAmt.ToString()
                            + "," + iafterDiscAmt.ToString()
                            + ",0,0," + isaleAmt.ToString() + ",'','" + myOrdItem[i].type.ToString() + "','','" + info.Sellway + "'"
                            + ",'" + info.cashierId + "','" + info.cashierId + "','" + soperDate + "','0','" + info.ShiftNumber + "'"
                            + ",'" + sAccDate + "','" + soperDate + "',0,0,0,0,0,0"
                            + ",0,'" + info.cashierId + "','','0',0,'',''"
                            + ",0,'" + info.posNo + "',0,0,0,0,0"
                            + ",0,0,0,'" + myOrdItem[i].pluName.ToString() + "','" + myOrdItem[i].customerCode.ToString() + "'"
                            + ",'0','','','',1,0,getdate(),0,0)";
                        myADO.SQLList.Add(SQL);
                    }
                }

                //解析订单支付
                string hposPayInfoJson = info.hposPayInfoJson;
                if ((hposPayInfoJson==null) ||(hposPayInfoJson.Length == 0)){

                }else
                {
                    List<c_postran.tranpay> myOrdPay = JsonConvert.DeserializeObject<List<c_postran.tranpay>>(info.hposPayInfoJson);//反序列化
                    for (int i = 0; i < myOrdPay.Count; i++)
                    {
                        //Console.WriteLine(myOrdItem[i].pluName);
                        SQL = "insert into epos.dbo.pos_tranpay(itemseq,flowno,SaleAmt,WarehouseID,payWay"
                            + ",sellWay,cardNo,vipNo,coinNo,coinRate,OverAmt,operDate,operId"
                            + ",Remark,voucherNo,UploadFlag,ShiftFlowNo,AccDate,vipbalance"
                            + ",vippoint,PosNo,custId,ulFlag,fCreateDate)"
                            + " values(" + (i + 1).ToString() + ",'" + info.tranNumber + "'," + myOrdPay[i].payprice.ToString()
                            + ",'" + info.storeId + "','" + myOrdPay[i].paychannel.ToString() + "'"
                            + ",'" + info.Sellway + "','','',0,0,0,'" + soperDate + "','" + info.cashierId + "'"
                            + ",'',0,'N','" + info.ShiftNumber + "','" + sAccDate + "',0"
                            + ",0,'" + info.posNo + "',0,'0',getdate())";
                        myADO.SQLList.Add(SQL);
                    }
                }

                SQL = "insert into epos.dbo.pos_tranhead(Accdate,Warehouseid,Flowno,Sellway"
                    + " ,GrosalAMT,DiscAMT,SaleAmt,OverAmt,ChgAmt,beforeDiscAmt,afterDiscAmt"
                    + "  ,operId,OperDate,saleMan,isInRoom,Deskproperty"
                    + "  ,CustNumber,CustManNumber,CustWoManNumber,CustChildNumber,CustWoMan,CustZWoman,CustYWoman,CustOMan,CustOWoman"
                    + "  ,ShiftFlowNo,uploadFlag,custId,MMDiscAmt,AccFlag,PosNo"
                    + "  ,tasteAmt,vipNo,vippoint,vippointToMoney,HaveServiceAmt,TaxAmt,fCreateDate,deskNo,ulFlag)"
                    + " values('" + sAccDate + "','" + info.storeId + "','" + info.tranNumber + "','"+info.Sellway+"'"
                    + "," + tSaleAmt.ToString() + "+" + tDiscAMT.ToString()
                    + "," + tDiscAMT.ToString()
                    + "," + tSaleAmt.ToString()
                    + ",0,0,"+ tDiscAMT.ToString() + ",0"
                    + ",'" + info.cashierId + "','" + soperDate + "','" + info.cashierId + "'," + "'Y'" + ",'00'"
                    + ",1,1,0,0,0,0,0,0,0"
                    + ",'" + info.ShiftNumber + "','0','101',0,'0','" + info.posNo + "'"
                    + ",0,'',0,0,0,0,getdate(),0,0"
                    + ")";
                myADO.SQLList.Add(SQL);


                bool IsOk = false;
                string sError = string.Empty;
                myADO.doSave(out IsOk, out sError);

                //if (IsOk)
                //{
                //    SQL = " exec Proc_SetPosOrder '" + info.storeId + "','" + sOrdId + "'";
                //    myADO.doexec(SQL);
                //}
                //返回

                if (!IsOk)
                {
                    myOrdDataInfo.result = "1";
                    myOrdDataInfo.status = "false";
                    myOrdDataInfo.msg = sError;
                }

                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + "3.5 tranNumber:" + info.tranNumber);
                return myOrdDataInfo;
            }
            catch (Exception ex)
            {
                Console.WriteLine(DateTime.Now.ToLongTimeString().ToString() + "103.tranNumber error:" + ex.Message);
                Log.doWriteLog(1, "103.tranNumber error:" + ex.Message);
                s_postran myOrdDataInfo = new s_postran();
                myOrdDataInfo.result = "1";
                myOrdDataInfo.status = "false";
                myOrdDataInfo.msg = "tranNumber error:" + ex.Message;
                return myOrdDataInfo;
            }

        }


    }
}
